starsofchance commited on
Commit
a8f5cdb
·
verified ·
1 Parent(s): d9f2f28

Added original tesst cases and the ground truth file

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. OWASP DATASET/BenchmarkTest00001.java +105 -0
  2. OWASP DATASET/BenchmarkTest00002.java +92 -0
  3. OWASP DATASET/BenchmarkTest00003.java +119 -0
  4. OWASP DATASET/BenchmarkTest00004.java +75 -0
  5. OWASP DATASET/BenchmarkTest00005.java +122 -0
  6. OWASP DATASET/BenchmarkTest00006.java +77 -0
  7. OWASP DATASET/BenchmarkTest00007.java +70 -0
  8. OWASP DATASET/BenchmarkTest00008.java +68 -0
  9. OWASP DATASET/BenchmarkTest00009.java +124 -0
  10. OWASP DATASET/BenchmarkTest00010.java +116 -0
  11. OWASP DATASET/BenchmarkTest00011.java +70 -0
  12. OWASP DATASET/BenchmarkTest00012.java +106 -0
  13. OWASP DATASET/BenchmarkTest00013.java +58 -0
  14. OWASP DATASET/BenchmarkTest00014.java +58 -0
  15. OWASP DATASET/BenchmarkTest00015.java +79 -0
  16. OWASP DATASET/BenchmarkTest00016.java +83 -0
  17. OWASP DATASET/BenchmarkTest00017.java +72 -0
  18. OWASP DATASET/BenchmarkTest00018.java +68 -0
  19. OWASP DATASET/BenchmarkTest00019.java +107 -0
  20. OWASP DATASET/BenchmarkTest00020.java +151 -0
  21. OWASP DATASET/BenchmarkTest00021.java +97 -0
  22. OWASP DATASET/BenchmarkTest00022.java +96 -0
  23. OWASP DATASET/BenchmarkTest00023.java +96 -0
  24. OWASP DATASET/BenchmarkTest00024.java +68 -0
  25. OWASP DATASET/BenchmarkTest00025.java +66 -0
  26. OWASP DATASET/BenchmarkTest00026.java +76 -0
  27. OWASP DATASET/BenchmarkTest00027.java +61 -0
  28. OWASP DATASET/BenchmarkTest00028.java +77 -0
  29. OWASP DATASET/BenchmarkTest00029.java +104 -0
  30. OWASP DATASET/BenchmarkTest00030.java +55 -0
  31. OWASP DATASET/BenchmarkTest00031.java +60 -0
  32. OWASP DATASET/BenchmarkTest00032.java +68 -0
  33. OWASP DATASET/BenchmarkTest00033.java +80 -0
  34. OWASP DATASET/BenchmarkTest00034.java +65 -0
  35. OWASP DATASET/BenchmarkTest00035.java +122 -0
  36. OWASP DATASET/BenchmarkTest00036.java +68 -0
  37. OWASP DATASET/BenchmarkTest00037.java +82 -0
  38. OWASP DATASET/BenchmarkTest00038.java +97 -0
  39. OWASP DATASET/BenchmarkTest00039.java +83 -0
  40. OWASP DATASET/BenchmarkTest00040.java +65 -0
  41. OWASP DATASET/BenchmarkTest00041.java +56 -0
  42. OWASP DATASET/BenchmarkTest00042.java +103 -0
  43. OWASP DATASET/BenchmarkTest00043.java +63 -0
  44. OWASP DATASET/BenchmarkTest00044.java +98 -0
  45. OWASP DATASET/BenchmarkTest00045.java +72 -0
  46. OWASP DATASET/BenchmarkTest00046.java +98 -0
  47. OWASP DATASET/BenchmarkTest00047.java +75 -0
  48. OWASP DATASET/BenchmarkTest00048.java +74 -0
  49. OWASP DATASET/BenchmarkTest00049.java +74 -0
  50. OWASP DATASET/BenchmarkTest00050.java +152 -0
OWASP DATASET/BenchmarkTest00001.java ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * OWASP Benchmark v1.2
3
+ *
4
+ * <p>This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For
5
+ * details, please see <a
6
+ * href="https://owasp.org/www-project-benchmark/">https://owasp.org/www-project-benchmark/</a>.
7
+ *
8
+ * <p>The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms
9
+ * of the GNU General Public License as published by the Free Software Foundation, version 2.
10
+ *
11
+ * <p>The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY
12
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13
+ * PURPOSE. See the GNU General Public License for more details.
14
+ *
15
+ * @author Dave Wichers
16
+ * @created 2015
17
+ */
18
+ package org.owasp.benchmark.testcode;
19
+
20
+ import java.io.IOException;
21
+ import javax.servlet.ServletException;
22
+ import javax.servlet.annotation.WebServlet;
23
+ import javax.servlet.http.HttpServlet;
24
+ import javax.servlet.http.HttpServletRequest;
25
+ import javax.servlet.http.HttpServletResponse;
26
+
27
+ @WebServlet(value = "/pathtraver-00/BenchmarkTest00001")
28
+ public class BenchmarkTest00001 extends HttpServlet {
29
+
30
+ private static final long serialVersionUID = 1L;
31
+
32
+ @Override
33
+ public void doGet(HttpServletRequest request, HttpServletResponse response)
34
+ throws ServletException, IOException {
35
+ response.setContentType("text/html;charset=UTF-8");
36
+ javax.servlet.http.Cookie userCookie =
37
+ new javax.servlet.http.Cookie("BenchmarkTest00001", "FileName");
38
+ userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes
39
+ userCookie.setSecure(true);
40
+ userCookie.setPath(request.getRequestURI());
41
+ userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost());
42
+ response.addCookie(userCookie);
43
+ javax.servlet.RequestDispatcher rd =
44
+ request.getRequestDispatcher("/pathtraver-00/BenchmarkTest00001.html");
45
+ rd.include(request, response);
46
+ }
47
+
48
+ @Override
49
+ public void doPost(HttpServletRequest request, HttpServletResponse response)
50
+ throws ServletException, IOException {
51
+ // some code
52
+ response.setContentType("text/html;charset=UTF-8");
53
+
54
+ javax.servlet.http.Cookie[] theCookies = request.getCookies();
55
+
56
+ String param = "noCookieValueSupplied";
57
+ if (theCookies != null) {
58
+ for (javax.servlet.http.Cookie theCookie : theCookies) {
59
+ if (theCookie.getName().equals("BenchmarkTest00001")) {
60
+ param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8");
61
+ break;
62
+ }
63
+ }
64
+ }
65
+
66
+ String fileName = null;
67
+ java.io.FileInputStream fis = null;
68
+
69
+ try {
70
+ fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + param;
71
+ fis = new java.io.FileInputStream(new java.io.File(fileName));
72
+ byte[] b = new byte[1000];
73
+ int size = fis.read(b);
74
+ response.getWriter()
75
+ .println(
76
+ "The beginning of file: '"
77
+ + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)
78
+ + "' is:\n\n"
79
+ + org.owasp
80
+ .esapi
81
+ .ESAPI
82
+ .encoder()
83
+ .encodeForHTML(new String(b, 0, size)));
84
+ } catch (Exception e) {
85
+ System.out.println("Couldn't open FileInputStream on file: '" + fileName + "'");
86
+ response.getWriter()
87
+ .println(
88
+ "Problem getting FileInputStream: "
89
+ + org.owasp
90
+ .esapi
91
+ .ESAPI
92
+ .encoder()
93
+ .encodeForHTML(e.getMessage()));
94
+ } finally {
95
+ if (fis != null) {
96
+ try {
97
+ fis.close();
98
+ fis = null;
99
+ } catch (Exception e) {
100
+ // we tried...
101
+ }
102
+ }
103
+ }
104
+ }
105
+ }
OWASP DATASET/BenchmarkTest00002.java ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * OWASP Benchmark v1.2
3
+ *
4
+ * <p>This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For
5
+ * details, please see <a
6
+ * href="https://owasp.org/www-project-benchmark/">https://owasp.org/www-project-benchmark/</a>.
7
+ *
8
+ * <p>The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms
9
+ * of the GNU General Public License as published by the Free Software Foundation, version 2.
10
+ *
11
+ * <p>The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY
12
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13
+ * PURPOSE. See the GNU General Public License for more details.
14
+ *
15
+ * @author Dave Wichers
16
+ * @created 2015
17
+ */
18
+ package org.owasp.benchmark.testcode;
19
+
20
+ import java.io.IOException;
21
+ import javax.servlet.ServletException;
22
+ import javax.servlet.annotation.WebServlet;
23
+ import javax.servlet.http.HttpServlet;
24
+ import javax.servlet.http.HttpServletRequest;
25
+ import javax.servlet.http.HttpServletResponse;
26
+
27
+ @WebServlet(value = "/pathtraver-00/BenchmarkTest00002")
28
+ public class BenchmarkTest00002 extends HttpServlet {
29
+
30
+ private static final long serialVersionUID = 1L;
31
+
32
+ @Override
33
+ public void doGet(HttpServletRequest request, HttpServletResponse response)
34
+ throws ServletException, IOException {
35
+ response.setContentType("text/html;charset=UTF-8");
36
+ javax.servlet.http.Cookie userCookie =
37
+ new javax.servlet.http.Cookie("BenchmarkTest00002", "FileName");
38
+ userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes
39
+ userCookie.setSecure(true);
40
+ userCookie.setPath(request.getRequestURI());
41
+ userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost());
42
+ response.addCookie(userCookie);
43
+ javax.servlet.RequestDispatcher rd =
44
+ request.getRequestDispatcher("/pathtraver-00/BenchmarkTest00002.html");
45
+ rd.include(request, response);
46
+ }
47
+
48
+ @Override
49
+ public void doPost(HttpServletRequest request, HttpServletResponse response)
50
+ throws ServletException, IOException {
51
+ // some code
52
+ response.setContentType("text/html;charset=UTF-8");
53
+
54
+ javax.servlet.http.Cookie[] theCookies = request.getCookies();
55
+
56
+ String param = "noCookieValueSupplied";
57
+ if (theCookies != null) {
58
+ for (javax.servlet.http.Cookie theCookie : theCookies) {
59
+ if (theCookie.getName().equals("BenchmarkTest00002")) {
60
+ param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8");
61
+ break;
62
+ }
63
+ }
64
+ }
65
+
66
+ String fileName = null;
67
+ java.io.FileOutputStream fos = null;
68
+
69
+ try {
70
+ fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + param;
71
+
72
+ fos = new java.io.FileOutputStream(fileName, false);
73
+ response.getWriter()
74
+ .println(
75
+ "Now ready to write to file: "
76
+ + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName));
77
+
78
+ } catch (Exception e) {
79
+ System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'");
80
+ // System.out.println("File exception caught and swallowed: " + e.getMessage());
81
+ } finally {
82
+ if (fos != null) {
83
+ try {
84
+ fos.close();
85
+ fos = null;
86
+ } catch (Exception e) {
87
+ // we tried...
88
+ }
89
+ }
90
+ }
91
+ }
92
+ }
OWASP DATASET/BenchmarkTest00003.java ADDED
@@ -0,0 +1,119 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * OWASP Benchmark v1.2
3
+ *
4
+ * <p>This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For
5
+ * details, please see <a
6
+ * href="https://owasp.org/www-project-benchmark/">https://owasp.org/www-project-benchmark/</a>.
7
+ *
8
+ * <p>The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms
9
+ * of the GNU General Public License as published by the Free Software Foundation, version 2.
10
+ *
11
+ * <p>The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY
12
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13
+ * PURPOSE. See the GNU General Public License for more details.
14
+ *
15
+ * @author Dave Wichers
16
+ * @created 2015
17
+ */
18
+ package org.owasp.benchmark.testcode;
19
+
20
+ import java.io.IOException;
21
+ import javax.servlet.ServletException;
22
+ import javax.servlet.annotation.WebServlet;
23
+ import javax.servlet.http.HttpServlet;
24
+ import javax.servlet.http.HttpServletRequest;
25
+ import javax.servlet.http.HttpServletResponse;
26
+
27
+ @WebServlet(value = "/hash-00/BenchmarkTest00003")
28
+ public class BenchmarkTest00003 extends HttpServlet {
29
+
30
+ private static final long serialVersionUID = 1L;
31
+
32
+ @Override
33
+ public void doGet(HttpServletRequest request, HttpServletResponse response)
34
+ throws ServletException, IOException {
35
+ response.setContentType("text/html;charset=UTF-8");
36
+ javax.servlet.http.Cookie userCookie =
37
+ new javax.servlet.http.Cookie("BenchmarkTest00003", "someSecret");
38
+ userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes
39
+ userCookie.setSecure(true);
40
+ userCookie.setPath(request.getRequestURI());
41
+ userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost());
42
+ response.addCookie(userCookie);
43
+ javax.servlet.RequestDispatcher rd =
44
+ request.getRequestDispatcher("/hash-00/BenchmarkTest00003.html");
45
+ rd.include(request, response);
46
+ }
47
+
48
+ @Override
49
+ public void doPost(HttpServletRequest request, HttpServletResponse response)
50
+ throws ServletException, IOException {
51
+ // some code
52
+ response.setContentType("text/html;charset=UTF-8");
53
+
54
+ javax.servlet.http.Cookie[] theCookies = request.getCookies();
55
+
56
+ String param = "noCookieValueSupplied";
57
+ if (theCookies != null) {
58
+ for (javax.servlet.http.Cookie theCookie : theCookies) {
59
+ if (theCookie.getName().equals("BenchmarkTest00003")) {
60
+ param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8");
61
+ break;
62
+ }
63
+ }
64
+ }
65
+
66
+ try {
67
+ java.util.Properties benchmarkprops = new java.util.Properties();
68
+ benchmarkprops.load(
69
+ this.getClass().getClassLoader().getResourceAsStream("benchmark.properties"));
70
+ String algorithm = benchmarkprops.getProperty("hashAlg1", "SHA512");
71
+ java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm);
72
+ byte[] input = {(byte) '?'};
73
+ Object inputParam = param;
74
+ if (inputParam instanceof String) input = ((String) inputParam).getBytes();
75
+ if (inputParam instanceof java.io.InputStream) {
76
+ byte[] strInput = new byte[1000];
77
+ int i = ((java.io.InputStream) inputParam).read(strInput);
78
+ if (i == -1) {
79
+ response.getWriter()
80
+ .println(
81
+ "This input source requires a POST, not a GET. Incompatible UI for the InputStream source.");
82
+ return;
83
+ }
84
+ input = java.util.Arrays.copyOf(strInput, i);
85
+ }
86
+ md.update(input);
87
+
88
+ byte[] result = md.digest();
89
+ java.io.File fileTarget =
90
+ new java.io.File(
91
+ new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR),
92
+ "passwordFile.txt");
93
+ java.io.FileWriter fw =
94
+ new java.io.FileWriter(fileTarget, true); // the true will append the new data
95
+ fw.write(
96
+ "hash_value="
97
+ + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true)
98
+ + "\n");
99
+ fw.close();
100
+ response.getWriter()
101
+ .println(
102
+ "Sensitive value '"
103
+ + org.owasp
104
+ .esapi
105
+ .ESAPI
106
+ .encoder()
107
+ .encodeForHTML(new String(input))
108
+ + "' hashed and stored<br/>");
109
+
110
+ } catch (java.security.NoSuchAlgorithmException e) {
111
+ System.out.println("Problem executing hash - TestCase");
112
+ throw new ServletException(e);
113
+ }
114
+
115
+ response.getWriter()
116
+ .println(
117
+ "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed");
118
+ }
119
+ }
OWASP DATASET/BenchmarkTest00004.java ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * OWASP Benchmark v1.2
3
+ *
4
+ * <p>This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For
5
+ * details, please see <a
6
+ * href="https://owasp.org/www-project-benchmark/">https://owasp.org/www-project-benchmark/</a>.
7
+ *
8
+ * <p>The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms
9
+ * of the GNU General Public License as published by the Free Software Foundation, version 2.
10
+ *
11
+ * <p>The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY
12
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13
+ * PURPOSE. See the GNU General Public License for more details.
14
+ *
15
+ * @author Dave Wichers
16
+ * @created 2015
17
+ */
18
+ package org.owasp.benchmark.testcode;
19
+
20
+ import java.io.IOException;
21
+ import javax.servlet.ServletException;
22
+ import javax.servlet.annotation.WebServlet;
23
+ import javax.servlet.http.HttpServlet;
24
+ import javax.servlet.http.HttpServletRequest;
25
+ import javax.servlet.http.HttpServletResponse;
26
+
27
+ @WebServlet(value = "/trustbound-00/BenchmarkTest00004")
28
+ public class BenchmarkTest00004 extends HttpServlet {
29
+
30
+ private static final long serialVersionUID = 1L;
31
+
32
+ @Override
33
+ public void doGet(HttpServletRequest request, HttpServletResponse response)
34
+ throws ServletException, IOException {
35
+ response.setContentType("text/html;charset=UTF-8");
36
+ javax.servlet.http.Cookie userCookie =
37
+ new javax.servlet.http.Cookie("BenchmarkTest00004", "color");
38
+ userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes
39
+ userCookie.setSecure(true);
40
+ userCookie.setPath(request.getRequestURI());
41
+ userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost());
42
+ response.addCookie(userCookie);
43
+ javax.servlet.RequestDispatcher rd =
44
+ request.getRequestDispatcher("/trustbound-00/BenchmarkTest00004.html");
45
+ rd.include(request, response);
46
+ }
47
+
48
+ @Override
49
+ public void doPost(HttpServletRequest request, HttpServletResponse response)
50
+ throws ServletException, IOException {
51
+ // some code
52
+ response.setContentType("text/html;charset=UTF-8");
53
+
54
+ javax.servlet.http.Cookie[] theCookies = request.getCookies();
55
+
56
+ String param = "noCookieValueSupplied";
57
+ if (theCookies != null) {
58
+ for (javax.servlet.http.Cookie theCookie : theCookies) {
59
+ if (theCookie.getName().equals("BenchmarkTest00004")) {
60
+ param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8");
61
+ break;
62
+ }
63
+ }
64
+ }
65
+
66
+ // javax.servlet.http.HttpSession.setAttribute(java.lang.String^,java.lang.Object)
67
+ request.getSession().setAttribute(param, "10340");
68
+
69
+ response.getWriter()
70
+ .println(
71
+ "Item: '"
72
+ + org.owasp.benchmark.helpers.Utils.encodeForHTML(param)
73
+ + "' with value: '10340' saved in session.");
74
+ }
75
+ }
OWASP DATASET/BenchmarkTest00005.java ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * OWASP Benchmark v1.2
3
+ *
4
+ * <p>This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For
5
+ * details, please see <a
6
+ * href="https://owasp.org/www-project-benchmark/">https://owasp.org/www-project-benchmark/</a>.
7
+ *
8
+ * <p>The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms
9
+ * of the GNU General Public License as published by the Free Software Foundation, version 2.
10
+ *
11
+ * <p>The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY
12
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13
+ * PURPOSE. See the GNU General Public License for more details.
14
+ *
15
+ * @author Dave Wichers
16
+ * @created 2015
17
+ */
18
+ package org.owasp.benchmark.testcode;
19
+
20
+ import java.io.IOException;
21
+ import javax.servlet.ServletException;
22
+ import javax.servlet.annotation.WebServlet;
23
+ import javax.servlet.http.HttpServlet;
24
+ import javax.servlet.http.HttpServletRequest;
25
+ import javax.servlet.http.HttpServletResponse;
26
+
27
+ @WebServlet(value = "/crypto-00/BenchmarkTest00005")
28
+ public class BenchmarkTest00005 extends HttpServlet {
29
+
30
+ private static final long serialVersionUID = 1L;
31
+
32
+ @Override
33
+ public void doGet(HttpServletRequest request, HttpServletResponse response)
34
+ throws ServletException, IOException {
35
+ doPost(request, response);
36
+ }
37
+
38
+ @Override
39
+ public void doPost(HttpServletRequest request, HttpServletResponse response)
40
+ throws ServletException, IOException {
41
+ // some code
42
+ response.setContentType("text/html;charset=UTF-8");
43
+
44
+ String param = "";
45
+ if (request.getHeader("BenchmarkTest00005") != null) {
46
+ param = request.getHeader("BenchmarkTest00005");
47
+ }
48
+
49
+ // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter().
50
+ param = java.net.URLDecoder.decode(param, "UTF-8");
51
+
52
+ // Code based on example from:
53
+ // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/
54
+ // 8-byte initialization vector
55
+ // byte[] iv = {
56
+ // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2,
57
+ // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033
58
+ // };
59
+ java.security.SecureRandom random = new java.security.SecureRandom();
60
+ byte[] iv = random.generateSeed(8); // DES requires 8 byte keys
61
+
62
+ try {
63
+ javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("DES/CBC/PKCS5Padding");
64
+
65
+ // Prepare the cipher to encrypt
66
+ javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey();
67
+ java.security.spec.AlgorithmParameterSpec paramSpec =
68
+ new javax.crypto.spec.IvParameterSpec(iv);
69
+ c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec);
70
+
71
+ // encrypt and store the results
72
+ byte[] input = {(byte) '?'};
73
+ Object inputParam = param;
74
+ if (inputParam instanceof String) input = ((String) inputParam).getBytes();
75
+ if (inputParam instanceof java.io.InputStream) {
76
+ byte[] strInput = new byte[1000];
77
+ int i = ((java.io.InputStream) inputParam).read(strInput);
78
+ if (i == -1) {
79
+ response.getWriter()
80
+ .println(
81
+ "This input source requires a POST, not a GET. Incompatible UI for the InputStream source.");
82
+ return;
83
+ }
84
+ input = java.util.Arrays.copyOf(strInput, i);
85
+ }
86
+ byte[] result = c.doFinal(input);
87
+
88
+ java.io.File fileTarget =
89
+ new java.io.File(
90
+ new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR),
91
+ "passwordFile.txt");
92
+ java.io.FileWriter fw =
93
+ new java.io.FileWriter(fileTarget, true); // the true will append the new data
94
+ fw.write(
95
+ "secret_value="
96
+ + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true)
97
+ + "\n");
98
+ fw.close();
99
+ response.getWriter()
100
+ .println(
101
+ "Sensitive value: '"
102
+ + org.owasp
103
+ .esapi
104
+ .ESAPI
105
+ .encoder()
106
+ .encodeForHTML(new String(input))
107
+ + "' encrypted and stored<br/>");
108
+
109
+ } catch (java.security.NoSuchAlgorithmException
110
+ | javax.crypto.NoSuchPaddingException
111
+ | javax.crypto.IllegalBlockSizeException
112
+ | javax.crypto.BadPaddingException
113
+ | java.security.InvalidKeyException
114
+ | java.security.InvalidAlgorithmParameterException e) {
115
+ response.getWriter()
116
+ .println(
117
+ "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case");
118
+ e.printStackTrace(response.getWriter());
119
+ throw new ServletException(e);
120
+ }
121
+ }
122
+ }
OWASP DATASET/BenchmarkTest00006.java ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * OWASP Benchmark v1.2
3
+ *
4
+ * <p>This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For
5
+ * details, please see <a
6
+ * href="https://owasp.org/www-project-benchmark/">https://owasp.org/www-project-benchmark/</a>.
7
+ *
8
+ * <p>The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms
9
+ * of the GNU General Public License as published by the Free Software Foundation, version 2.
10
+ *
11
+ * <p>The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY
12
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13
+ * PURPOSE. See the GNU General Public License for more details.
14
+ *
15
+ * @author Dave Wichers
16
+ * @created 2015
17
+ */
18
+ package org.owasp.benchmark.testcode;
19
+
20
+ import java.io.IOException;
21
+ import javax.servlet.ServletException;
22
+ import javax.servlet.annotation.WebServlet;
23
+ import javax.servlet.http.HttpServlet;
24
+ import javax.servlet.http.HttpServletRequest;
25
+ import javax.servlet.http.HttpServletResponse;
26
+
27
+ @WebServlet(value = "/cmdi-00/BenchmarkTest00006")
28
+ public class BenchmarkTest00006 extends HttpServlet {
29
+
30
+ private static final long serialVersionUID = 1L;
31
+
32
+ @Override
33
+ public void doGet(HttpServletRequest request, HttpServletResponse response)
34
+ throws ServletException, IOException {
35
+ doPost(request, response);
36
+ }
37
+
38
+ @Override
39
+ public void doPost(HttpServletRequest request, HttpServletResponse response)
40
+ throws ServletException, IOException {
41
+ // some code
42
+ response.setContentType("text/html;charset=UTF-8");
43
+
44
+ String param = "";
45
+ if (request.getHeader("BenchmarkTest00006") != null) {
46
+ param = request.getHeader("BenchmarkTest00006");
47
+ }
48
+
49
+ // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter().
50
+ param = java.net.URLDecoder.decode(param, "UTF-8");
51
+
52
+ java.util.List<String> argList = new java.util.ArrayList<String>();
53
+
54
+ String osName = System.getProperty("os.name");
55
+ if (osName.indexOf("Windows") != -1) {
56
+ argList.add("cmd.exe");
57
+ argList.add("/c");
58
+ } else {
59
+ argList.add("sh");
60
+ argList.add("-c");
61
+ }
62
+ argList.add("echo " + param);
63
+
64
+ ProcessBuilder pb = new ProcessBuilder();
65
+
66
+ pb.command(argList);
67
+
68
+ try {
69
+ Process p = pb.start();
70
+ org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response);
71
+ } catch (IOException e) {
72
+ System.out.println(
73
+ "Problem executing cmdi - java.lang.ProcessBuilder(java.util.List) Test Case");
74
+ throw new ServletException(e);
75
+ }
76
+ }
77
+ }
OWASP DATASET/BenchmarkTest00007.java ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * OWASP Benchmark v1.2
3
+ *
4
+ * <p>This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For
5
+ * details, please see <a
6
+ * href="https://owasp.org/www-project-benchmark/">https://owasp.org/www-project-benchmark/</a>.
7
+ *
8
+ * <p>The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms
9
+ * of the GNU General Public License as published by the Free Software Foundation, version 2.
10
+ *
11
+ * <p>The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY
12
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13
+ * PURPOSE. See the GNU General Public License for more details.
14
+ *
15
+ * @author Dave Wichers
16
+ * @created 2015
17
+ */
18
+ package org.owasp.benchmark.testcode;
19
+
20
+ import java.io.IOException;
21
+ import javax.servlet.ServletException;
22
+ import javax.servlet.annotation.WebServlet;
23
+ import javax.servlet.http.HttpServlet;
24
+ import javax.servlet.http.HttpServletRequest;
25
+ import javax.servlet.http.HttpServletResponse;
26
+
27
+ @WebServlet(value = "/cmdi-00/BenchmarkTest00007")
28
+ public class BenchmarkTest00007 extends HttpServlet {
29
+
30
+ private static final long serialVersionUID = 1L;
31
+
32
+ @Override
33
+ public void doGet(HttpServletRequest request, HttpServletResponse response)
34
+ throws ServletException, IOException {
35
+ doPost(request, response);
36
+ }
37
+
38
+ @Override
39
+ public void doPost(HttpServletRequest request, HttpServletResponse response)
40
+ throws ServletException, IOException {
41
+ // some code
42
+ response.setContentType("text/html;charset=UTF-8");
43
+
44
+ String param = "";
45
+ if (request.getHeader("BenchmarkTest00007") != null) {
46
+ param = request.getHeader("BenchmarkTest00007");
47
+ }
48
+
49
+ // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter().
50
+ param = java.net.URLDecoder.decode(param, "UTF-8");
51
+
52
+ String cmd =
53
+ org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString(
54
+ this.getClass().getClassLoader());
55
+ String[] args = {cmd};
56
+ String[] argsEnv = {param};
57
+
58
+ Runtime r = Runtime.getRuntime();
59
+
60
+ try {
61
+ Process p = r.exec(args, argsEnv);
62
+ org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response);
63
+ } catch (IOException e) {
64
+ System.out.println("Problem executing cmdi - TestCase");
65
+ response.getWriter()
66
+ .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage()));
67
+ return;
68
+ }
69
+ }
70
+ }
OWASP DATASET/BenchmarkTest00008.java ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * OWASP Benchmark v1.2
3
+ *
4
+ * <p>This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For
5
+ * details, please see <a
6
+ * href="https://owasp.org/www-project-benchmark/">https://owasp.org/www-project-benchmark/</a>.
7
+ *
8
+ * <p>The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms
9
+ * of the GNU General Public License as published by the Free Software Foundation, version 2.
10
+ *
11
+ * <p>The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY
12
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13
+ * PURPOSE. See the GNU General Public License for more details.
14
+ *
15
+ * @author Dave Wichers
16
+ * @created 2015
17
+ */
18
+ package org.owasp.benchmark.testcode;
19
+
20
+ import java.io.IOException;
21
+ import javax.servlet.ServletException;
22
+ import javax.servlet.annotation.WebServlet;
23
+ import javax.servlet.http.HttpServlet;
24
+ import javax.servlet.http.HttpServletRequest;
25
+ import javax.servlet.http.HttpServletResponse;
26
+
27
+ @WebServlet(value = "/sqli-00/BenchmarkTest00008")
28
+ public class BenchmarkTest00008 extends HttpServlet {
29
+
30
+ private static final long serialVersionUID = 1L;
31
+
32
+ @Override
33
+ public void doGet(HttpServletRequest request, HttpServletResponse response)
34
+ throws ServletException, IOException {
35
+ doPost(request, response);
36
+ }
37
+
38
+ @Override
39
+ public void doPost(HttpServletRequest request, HttpServletResponse response)
40
+ throws ServletException, IOException {
41
+ // some code
42
+ response.setContentType("text/html;charset=UTF-8");
43
+
44
+ String param = "";
45
+ if (request.getHeader("BenchmarkTest00008") != null) {
46
+ param = request.getHeader("BenchmarkTest00008");
47
+ }
48
+
49
+ // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter().
50
+ param = java.net.URLDecoder.decode(param, "UTF-8");
51
+
52
+ String sql = "{call " + param + "}";
53
+
54
+ try {
55
+ java.sql.Connection connection =
56
+ org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection();
57
+ java.sql.CallableStatement statement = connection.prepareCall(sql);
58
+ java.sql.ResultSet rs = statement.executeQuery();
59
+ org.owasp.benchmark.helpers.DatabaseHelper.printResults(rs, sql, response);
60
+
61
+ } catch (java.sql.SQLException e) {
62
+ if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) {
63
+ response.getWriter().println("Error processing request.");
64
+ return;
65
+ } else throw new ServletException(e);
66
+ }
67
+ }
68
+ }
OWASP DATASET/BenchmarkTest00009.java ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * OWASP Benchmark v1.2
3
+ *
4
+ * <p>This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For
5
+ * details, please see <a
6
+ * href="https://owasp.org/www-project-benchmark/">https://owasp.org/www-project-benchmark/</a>.
7
+ *
8
+ * <p>The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms
9
+ * of the GNU General Public License as published by the Free Software Foundation, version 2.
10
+ *
11
+ * <p>The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY
12
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13
+ * PURPOSE. See the GNU General Public License for more details.
14
+ *
15
+ * @author Dave Wichers
16
+ * @created 2015
17
+ */
18
+ package org.owasp.benchmark.testcode;
19
+
20
+ import java.io.IOException;
21
+ import javax.servlet.ServletException;
22
+ import javax.servlet.annotation.WebServlet;
23
+ import javax.servlet.http.HttpServlet;
24
+ import javax.servlet.http.HttpServletRequest;
25
+ import javax.servlet.http.HttpServletResponse;
26
+
27
+ @WebServlet(value = "/hash-00/BenchmarkTest00009")
28
+ public class BenchmarkTest00009 extends HttpServlet {
29
+
30
+ private static final long serialVersionUID = 1L;
31
+
32
+ @Override
33
+ public void doGet(HttpServletRequest request, HttpServletResponse response)
34
+ throws ServletException, IOException {
35
+ doPost(request, response);
36
+ }
37
+
38
+ @Override
39
+ public void doPost(HttpServletRequest request, HttpServletResponse response)
40
+ throws ServletException, IOException {
41
+ // some code
42
+ response.setContentType("text/html;charset=UTF-8");
43
+
44
+ String param = "";
45
+ java.util.Enumeration<String> names = request.getHeaderNames();
46
+ while (names.hasMoreElements()) {
47
+ String name = (String) names.nextElement();
48
+
49
+ if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) {
50
+ continue; // If standard header, move on to next one
51
+ }
52
+
53
+ java.util.Enumeration<String> values = request.getHeaders(name);
54
+ if (values != null && values.hasMoreElements()) {
55
+ param = name; // Grabs the name of the first non-standard header as the parameter
56
+ // value
57
+ break;
58
+ }
59
+ }
60
+ // Note: We don't URL decode header names because people don't normally do that
61
+
62
+ java.security.Provider[] provider = java.security.Security.getProviders();
63
+ java.security.MessageDigest md;
64
+
65
+ try {
66
+ if (provider.length > 1) {
67
+
68
+ md = java.security.MessageDigest.getInstance("sha-384", provider[0]);
69
+ } else {
70
+ md = java.security.MessageDigest.getInstance("sha-384", "SUN");
71
+ }
72
+ byte[] input = {(byte) '?'};
73
+ Object inputParam = param;
74
+ if (inputParam instanceof String) input = ((String) inputParam).getBytes();
75
+ if (inputParam instanceof java.io.InputStream) {
76
+ byte[] strInput = new byte[1000];
77
+ int i = ((java.io.InputStream) inputParam).read(strInput);
78
+ if (i == -1) {
79
+ response.getWriter()
80
+ .println(
81
+ "This input source requires a POST, not a GET. Incompatible UI for the InputStream source.");
82
+ return;
83
+ }
84
+ input = java.util.Arrays.copyOf(strInput, i);
85
+ }
86
+ md.update(input);
87
+
88
+ byte[] result = md.digest();
89
+ java.io.File fileTarget =
90
+ new java.io.File(
91
+ new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR),
92
+ "passwordFile.txt");
93
+ java.io.FileWriter fw =
94
+ new java.io.FileWriter(fileTarget, true); // the true will append the new data
95
+ fw.write(
96
+ "hash_value="
97
+ + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true)
98
+ + "\n");
99
+ fw.close();
100
+ response.getWriter()
101
+ .println(
102
+ "Sensitive value '"
103
+ + org.owasp
104
+ .esapi
105
+ .ESAPI
106
+ .encoder()
107
+ .encodeForHTML(new String(input))
108
+ + "' hashed and stored<br/>");
109
+
110
+ } catch (java.security.NoSuchAlgorithmException e) {
111
+ System.out.println(
112
+ "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)");
113
+ throw new ServletException(e);
114
+ } catch (java.security.NoSuchProviderException e) {
115
+ System.out.println(
116
+ "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)");
117
+ throw new ServletException(e);
118
+ }
119
+
120
+ response.getWriter()
121
+ .println(
122
+ "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider) executed");
123
+ }
124
+ }
OWASP DATASET/BenchmarkTest00010.java ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * OWASP Benchmark v1.2
3
+ *
4
+ * <p>This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For
5
+ * details, please see <a
6
+ * href="https://owasp.org/www-project-benchmark/">https://owasp.org/www-project-benchmark/</a>.
7
+ *
8
+ * <p>The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms
9
+ * of the GNU General Public License as published by the Free Software Foundation, version 2.
10
+ *
11
+ * <p>The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY
12
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13
+ * PURPOSE. See the GNU General Public License for more details.
14
+ *
15
+ * @author Dave Wichers
16
+ * @created 2015
17
+ */
18
+ package org.owasp.benchmark.testcode;
19
+
20
+ import java.io.IOException;
21
+ import javax.servlet.ServletException;
22
+ import javax.servlet.annotation.WebServlet;
23
+ import javax.servlet.http.HttpServlet;
24
+ import javax.servlet.http.HttpServletRequest;
25
+ import javax.servlet.http.HttpServletResponse;
26
+
27
+ @WebServlet(value = "/weakrand-00/BenchmarkTest00010")
28
+ public class BenchmarkTest00010 extends HttpServlet {
29
+
30
+ private static final long serialVersionUID = 1L;
31
+
32
+ @Override
33
+ public void doGet(HttpServletRequest request, HttpServletResponse response)
34
+ throws ServletException, IOException {
35
+ doPost(request, response);
36
+ }
37
+
38
+ @Override
39
+ public void doPost(HttpServletRequest request, HttpServletResponse response)
40
+ throws ServletException, IOException {
41
+ // some code
42
+ response.setContentType("text/html;charset=UTF-8");
43
+
44
+ String param = "";
45
+ java.util.Enumeration<String> names = request.getHeaderNames();
46
+ while (names.hasMoreElements()) {
47
+ String name = (String) names.nextElement();
48
+
49
+ if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) {
50
+ continue; // If standard header, move on to next one
51
+ }
52
+
53
+ java.util.Enumeration<String> values = request.getHeaders(name);
54
+ if (values != null && values.hasMoreElements()) {
55
+ param = name; // Grabs the name of the first non-standard header as the parameter
56
+ // value
57
+ break;
58
+ }
59
+ }
60
+ // Note: We don't URL decode header names because people don't normally do that
61
+
62
+ try {
63
+ int randNumber = java.security.SecureRandom.getInstance("SHA1PRNG").nextInt(99);
64
+ String rememberMeKey = Integer.toString(randNumber);
65
+
66
+ String user = "SafeInga";
67
+ String fullClassName = this.getClass().getName();
68
+ String testCaseNumber =
69
+ fullClassName.substring(
70
+ fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length());
71
+ user += testCaseNumber;
72
+
73
+ String cookieName = "rememberMe" + testCaseNumber;
74
+
75
+ boolean foundUser = false;
76
+ javax.servlet.http.Cookie[] cookies = request.getCookies();
77
+ if (cookies != null) {
78
+ for (int i = 0; !foundUser && i < cookies.length; i++) {
79
+ javax.servlet.http.Cookie cookie = cookies[i];
80
+ if (cookieName.equals(cookie.getName())) {
81
+ if (cookie.getValue()
82
+ .equals(request.getSession().getAttribute(cookieName))) {
83
+ foundUser = true;
84
+ }
85
+ }
86
+ }
87
+ }
88
+
89
+ if (foundUser) {
90
+ response.getWriter().println("Welcome back: " + user + "<br/>");
91
+ } else {
92
+ javax.servlet.http.Cookie rememberMe =
93
+ new javax.servlet.http.Cookie(cookieName, rememberMeKey);
94
+ rememberMe.setSecure(true);
95
+ rememberMe.setHttpOnly(true);
96
+ rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet
97
+ // e.g., /benchmark/sql-01/BenchmarkTest01001
98
+ request.getSession().setAttribute(cookieName, rememberMeKey);
99
+ response.addCookie(rememberMe);
100
+ response.getWriter()
101
+ .println(
102
+ user
103
+ + " has been remembered with cookie: "
104
+ + rememberMe.getName()
105
+ + " whose value is: "
106
+ + rememberMe.getValue()
107
+ + "<br/>");
108
+ }
109
+ } catch (java.security.NoSuchAlgorithmException e) {
110
+ System.out.println("Problem executing SecureRandom.nextInt(int) - TestCase");
111
+ throw new ServletException(e);
112
+ }
113
+ response.getWriter()
114
+ .println("Weak Randomness Test java.security.SecureRandom.nextInt(int) executed");
115
+ }
116
+ }
OWASP DATASET/BenchmarkTest00011.java ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * OWASP Benchmark v1.2
3
+ *
4
+ * <p>This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For
5
+ * details, please see <a
6
+ * href="https://owasp.org/www-project-benchmark/">https://owasp.org/www-project-benchmark/</a>.
7
+ *
8
+ * <p>The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms
9
+ * of the GNU General Public License as published by the Free Software Foundation, version 2.
10
+ *
11
+ * <p>The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY
12
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13
+ * PURPOSE. See the GNU General Public License for more details.
14
+ *
15
+ * @author Dave Wichers
16
+ * @created 2015
17
+ */
18
+ package org.owasp.benchmark.testcode;
19
+
20
+ import java.io.IOException;
21
+ import javax.servlet.ServletException;
22
+ import javax.servlet.annotation.WebServlet;
23
+ import javax.servlet.http.HttpServlet;
24
+ import javax.servlet.http.HttpServletRequest;
25
+ import javax.servlet.http.HttpServletResponse;
26
+
27
+ @WebServlet(value = "/pathtraver-00/BenchmarkTest00011")
28
+ public class BenchmarkTest00011 extends HttpServlet {
29
+
30
+ private static final long serialVersionUID = 1L;
31
+
32
+ @Override
33
+ public void doGet(HttpServletRequest request, HttpServletResponse response)
34
+ throws ServletException, IOException {
35
+ doPost(request, response);
36
+ }
37
+
38
+ @Override
39
+ public void doPost(HttpServletRequest request, HttpServletResponse response)
40
+ throws ServletException, IOException {
41
+ // some code
42
+ response.setContentType("text/html;charset=UTF-8");
43
+
44
+ String param = "";
45
+ java.util.Enumeration<String> headers = request.getHeaders("BenchmarkTest00011");
46
+
47
+ if (headers != null && headers.hasMoreElements()) {
48
+ param = headers.nextElement(); // just grab first element
49
+ }
50
+
51
+ // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters().
52
+ param = java.net.URLDecoder.decode(param, "UTF-8");
53
+
54
+ java.io.File fileTarget = new java.io.File(param, "/Test.txt");
55
+ response.getWriter()
56
+ .println(
57
+ "Access to file: '"
58
+ + org.owasp
59
+ .esapi
60
+ .ESAPI
61
+ .encoder()
62
+ .encodeForHTML(fileTarget.toString())
63
+ + "' created.");
64
+ if (fileTarget.exists()) {
65
+ response.getWriter().println(" And file already exists.");
66
+ } else {
67
+ response.getWriter().println(" But file doesn't exist yet.");
68
+ }
69
+ }
70
+ }
OWASP DATASET/BenchmarkTest00012.java ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * OWASP Benchmark v1.2
3
+ *
4
+ * <p>This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For
5
+ * details, please see <a
6
+ * href="https://owasp.org/www-project-benchmark/">https://owasp.org/www-project-benchmark/</a>.
7
+ *
8
+ * <p>The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms
9
+ * of the GNU General Public License as published by the Free Software Foundation, version 2.
10
+ *
11
+ * <p>The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY
12
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13
+ * PURPOSE. See the GNU General Public License for more details.
14
+ *
15
+ * @author Dave Wichers
16
+ * @created 2015
17
+ */
18
+ package org.owasp.benchmark.testcode;
19
+
20
+ import java.io.IOException;
21
+ import javax.servlet.ServletException;
22
+ import javax.servlet.annotation.WebServlet;
23
+ import javax.servlet.http.HttpServlet;
24
+ import javax.servlet.http.HttpServletRequest;
25
+ import javax.servlet.http.HttpServletResponse;
26
+
27
+ @WebServlet(value = "/ldapi-00/BenchmarkTest00012")
28
+ public class BenchmarkTest00012 extends HttpServlet {
29
+
30
+ private static final long serialVersionUID = 1L;
31
+
32
+ @Override
33
+ public void doGet(HttpServletRequest request, HttpServletResponse response)
34
+ throws ServletException, IOException {
35
+ doPost(request, response);
36
+ }
37
+
38
+ @Override
39
+ public void doPost(HttpServletRequest request, HttpServletResponse response)
40
+ throws ServletException, IOException {
41
+ // some code
42
+ response.setContentType("text/html;charset=UTF-8");
43
+
44
+ String param = "";
45
+ java.util.Enumeration<String> headers = request.getHeaders("BenchmarkTest00012");
46
+
47
+ if (headers != null && headers.hasMoreElements()) {
48
+ param = headers.nextElement(); // just grab first element
49
+ }
50
+
51
+ // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters().
52
+ param = java.net.URLDecoder.decode(param, "UTF-8");
53
+
54
+ org.owasp.benchmark.helpers.LDAPManager ads = new org.owasp.benchmark.helpers.LDAPManager();
55
+ try {
56
+ response.setContentType("text/html;charset=UTF-8");
57
+ String base = "ou=users,ou=system";
58
+ javax.naming.directory.SearchControls sc = new javax.naming.directory.SearchControls();
59
+ sc.setSearchScope(javax.naming.directory.SearchControls.SUBTREE_SCOPE);
60
+ String filter = "(&(objectclass=person))(|(uid=" + param + ")(street={0}))";
61
+ Object[] filters = new Object[] {"The streetz 4 Ms bar"};
62
+
63
+ javax.naming.directory.DirContext ctx = ads.getDirContext();
64
+ javax.naming.directory.InitialDirContext idc =
65
+ (javax.naming.directory.InitialDirContext) ctx;
66
+ boolean found = false;
67
+ javax.naming.NamingEnumeration<javax.naming.directory.SearchResult> results =
68
+ idc.search(base, filter, filters, sc);
69
+ while (results.hasMore()) {
70
+ javax.naming.directory.SearchResult sr =
71
+ (javax.naming.directory.SearchResult) results.next();
72
+ javax.naming.directory.Attributes attrs = sr.getAttributes();
73
+
74
+ javax.naming.directory.Attribute attr = attrs.get("uid");
75
+ javax.naming.directory.Attribute attr2 = attrs.get("street");
76
+ if (attr != null) {
77
+ response.getWriter()
78
+ .println(
79
+ "LDAP query results:<br>"
80
+ + "Record found with name "
81
+ + attr.get()
82
+ + "<br>"
83
+ + "Address: "
84
+ + attr2.get()
85
+ + "<br>");
86
+ // System.out.println("record found " + attr.get());
87
+ found = true;
88
+ }
89
+ }
90
+ if (!found) {
91
+ response.getWriter()
92
+ .println(
93
+ "LDAP query results: nothing found for query: "
94
+ + org.owasp.esapi.ESAPI.encoder().encodeForHTML(filter));
95
+ }
96
+ } catch (javax.naming.NamingException e) {
97
+ throw new ServletException(e);
98
+ } finally {
99
+ try {
100
+ ads.closeDirContext();
101
+ } catch (Exception e) {
102
+ throw new ServletException(e);
103
+ }
104
+ }
105
+ }
106
+ }
OWASP DATASET/BenchmarkTest00013.java ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * OWASP Benchmark v1.2
3
+ *
4
+ * <p>This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For
5
+ * details, please see <a
6
+ * href="https://owasp.org/www-project-benchmark/">https://owasp.org/www-project-benchmark/</a>.
7
+ *
8
+ * <p>The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms
9
+ * of the GNU General Public License as published by the Free Software Foundation, version 2.
10
+ *
11
+ * <p>The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY
12
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13
+ * PURPOSE. See the GNU General Public License for more details.
14
+ *
15
+ * @author Dave Wichers
16
+ * @created 2015
17
+ */
18
+ package org.owasp.benchmark.testcode;
19
+
20
+ import java.io.IOException;
21
+ import javax.servlet.ServletException;
22
+ import javax.servlet.annotation.WebServlet;
23
+ import javax.servlet.http.HttpServlet;
24
+ import javax.servlet.http.HttpServletRequest;
25
+ import javax.servlet.http.HttpServletResponse;
26
+
27
+ @WebServlet(value = "/xss-00/BenchmarkTest00013")
28
+ public class BenchmarkTest00013 extends HttpServlet {
29
+
30
+ private static final long serialVersionUID = 1L;
31
+
32
+ @Override
33
+ public void doGet(HttpServletRequest request, HttpServletResponse response)
34
+ throws ServletException, IOException {
35
+ doPost(request, response);
36
+ }
37
+
38
+ @Override
39
+ public void doPost(HttpServletRequest request, HttpServletResponse response)
40
+ throws ServletException, IOException {
41
+ // some code
42
+ response.setContentType("text/html;charset=UTF-8");
43
+
44
+ String param = "";
45
+ java.util.Enumeration<String> headers = request.getHeaders("Referer");
46
+
47
+ if (headers != null && headers.hasMoreElements()) {
48
+ param = headers.nextElement(); // just grab first element
49
+ }
50
+
51
+ // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters().
52
+ param = java.net.URLDecoder.decode(param, "UTF-8");
53
+
54
+ response.setHeader("X-XSS-Protection", "0");
55
+ Object[] obj = {"a", "b"};
56
+ response.getWriter().format(java.util.Locale.US, param, obj);
57
+ }
58
+ }
OWASP DATASET/BenchmarkTest00014.java ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * OWASP Benchmark v1.2
3
+ *
4
+ * <p>This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For
5
+ * details, please see <a
6
+ * href="https://owasp.org/www-project-benchmark/">https://owasp.org/www-project-benchmark/</a>.
7
+ *
8
+ * <p>The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms
9
+ * of the GNU General Public License as published by the Free Software Foundation, version 2.
10
+ *
11
+ * <p>The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY
12
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13
+ * PURPOSE. See the GNU General Public License for more details.
14
+ *
15
+ * @author Dave Wichers
16
+ * @created 2015
17
+ */
18
+ package org.owasp.benchmark.testcode;
19
+
20
+ import java.io.IOException;
21
+ import javax.servlet.ServletException;
22
+ import javax.servlet.annotation.WebServlet;
23
+ import javax.servlet.http.HttpServlet;
24
+ import javax.servlet.http.HttpServletRequest;
25
+ import javax.servlet.http.HttpServletResponse;
26
+
27
+ @WebServlet(value = "/xss-00/BenchmarkTest00014")
28
+ public class BenchmarkTest00014 extends HttpServlet {
29
+
30
+ private static final long serialVersionUID = 1L;
31
+
32
+ @Override
33
+ public void doGet(HttpServletRequest request, HttpServletResponse response)
34
+ throws ServletException, IOException {
35
+ doPost(request, response);
36
+ }
37
+
38
+ @Override
39
+ public void doPost(HttpServletRequest request, HttpServletResponse response)
40
+ throws ServletException, IOException {
41
+ // some code
42
+ response.setContentType("text/html;charset=UTF-8");
43
+
44
+ String param = "";
45
+ java.util.Enumeration<String> headers = request.getHeaders("Referer");
46
+
47
+ if (headers != null && headers.hasMoreElements()) {
48
+ param = headers.nextElement(); // just grab first element
49
+ }
50
+
51
+ // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters().
52
+ param = java.net.URLDecoder.decode(param, "UTF-8");
53
+
54
+ response.setHeader("X-XSS-Protection", "0");
55
+ Object[] obj = {"a", "b"};
56
+ response.getWriter().format(param, obj);
57
+ }
58
+ }
OWASP DATASET/BenchmarkTest00015.java ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * OWASP Benchmark v1.2
3
+ *
4
+ * <p>This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For
5
+ * details, please see <a
6
+ * href="https://owasp.org/www-project-benchmark/">https://owasp.org/www-project-benchmark/</a>.
7
+ *
8
+ * <p>The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms
9
+ * of the GNU General Public License as published by the Free Software Foundation, version 2.
10
+ *
11
+ * <p>The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY
12
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13
+ * PURPOSE. See the GNU General Public License for more details.
14
+ *
15
+ * @author Dave Wichers
16
+ * @created 2015
17
+ */
18
+ package org.owasp.benchmark.testcode;
19
+
20
+ import java.io.IOException;
21
+ import javax.servlet.ServletException;
22
+ import javax.servlet.annotation.WebServlet;
23
+ import javax.servlet.http.HttpServlet;
24
+ import javax.servlet.http.HttpServletRequest;
25
+ import javax.servlet.http.HttpServletResponse;
26
+
27
+ @WebServlet(value = "/cmdi-00/BenchmarkTest00015")
28
+ public class BenchmarkTest00015 extends HttpServlet {
29
+
30
+ private static final long serialVersionUID = 1L;
31
+
32
+ @Override
33
+ public void doGet(HttpServletRequest request, HttpServletResponse response)
34
+ throws ServletException, IOException {
35
+ doPost(request, response);
36
+ }
37
+
38
+ @Override
39
+ public void doPost(HttpServletRequest request, HttpServletResponse response)
40
+ throws ServletException, IOException {
41
+ // some code
42
+ response.setContentType("text/html;charset=UTF-8");
43
+
44
+ String param = "";
45
+ java.util.Enumeration<String> headers = request.getHeaders("BenchmarkTest00015");
46
+
47
+ if (headers != null && headers.hasMoreElements()) {
48
+ param = headers.nextElement(); // just grab first element
49
+ }
50
+
51
+ // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters().
52
+ param = java.net.URLDecoder.decode(param, "UTF-8");
53
+
54
+ java.util.List<String> argList = new java.util.ArrayList<String>();
55
+
56
+ String osName = System.getProperty("os.name");
57
+ if (osName.indexOf("Windows") != -1) {
58
+ argList.add("cmd.exe");
59
+ argList.add("/c");
60
+ } else {
61
+ argList.add("sh");
62
+ argList.add("-c");
63
+ }
64
+ argList.add("echo " + param);
65
+
66
+ ProcessBuilder pb = new ProcessBuilder();
67
+
68
+ pb.command(argList);
69
+
70
+ try {
71
+ Process p = pb.start();
72
+ org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response);
73
+ } catch (IOException e) {
74
+ System.out.println(
75
+ "Problem executing cmdi - java.lang.ProcessBuilder(java.util.List) Test Case");
76
+ throw new ServletException(e);
77
+ }
78
+ }
79
+ }
OWASP DATASET/BenchmarkTest00016.java ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * OWASP Benchmark v1.2
3
+ *
4
+ * <p>This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For
5
+ * details, please see <a
6
+ * href="https://owasp.org/www-project-benchmark/">https://owasp.org/www-project-benchmark/</a>.
7
+ *
8
+ * <p>The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms
9
+ * of the GNU General Public License as published by the Free Software Foundation, version 2.
10
+ *
11
+ * <p>The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY
12
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13
+ * PURPOSE. See the GNU General Public License for more details.
14
+ *
15
+ * @author Dave Wichers
16
+ * @created 2015
17
+ */
18
+ package org.owasp.benchmark.testcode;
19
+
20
+ import java.io.IOException;
21
+ import javax.servlet.ServletException;
22
+ import javax.servlet.annotation.WebServlet;
23
+ import javax.servlet.http.HttpServlet;
24
+ import javax.servlet.http.HttpServletRequest;
25
+ import javax.servlet.http.HttpServletResponse;
26
+
27
+ @WebServlet(value = "/securecookie-00/BenchmarkTest00016")
28
+ public class BenchmarkTest00016 extends HttpServlet {
29
+
30
+ private static final long serialVersionUID = 1L;
31
+
32
+ @Override
33
+ public void doGet(HttpServletRequest request, HttpServletResponse response)
34
+ throws ServletException, IOException {
35
+ doPost(request, response);
36
+ }
37
+
38
+ @Override
39
+ public void doPost(HttpServletRequest request, HttpServletResponse response)
40
+ throws ServletException, IOException {
41
+ // some code
42
+ response.setContentType("text/html;charset=UTF-8");
43
+
44
+ String param = "";
45
+ java.util.Enumeration<String> headers = request.getHeaders("BenchmarkTest00016");
46
+
47
+ if (headers != null && headers.hasMoreElements()) {
48
+ param = headers.nextElement(); // just grab first element
49
+ }
50
+
51
+ // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters().
52
+ param = java.net.URLDecoder.decode(param, "UTF-8");
53
+
54
+ byte[] input = new byte[1000];
55
+ String str = "?";
56
+ Object inputParam = param;
57
+ if (inputParam instanceof String) str = ((String) inputParam);
58
+ if (inputParam instanceof java.io.InputStream) {
59
+ int i = ((java.io.InputStream) inputParam).read(input);
60
+ if (i == -1) {
61
+ response.getWriter()
62
+ .println(
63
+ "This input source requires a POST, not a GET. Incompatible UI for the InputStream source.");
64
+ return;
65
+ }
66
+ str = new String(input, 0, i);
67
+ }
68
+ if ("".equals(str)) str = "No cookie value supplied";
69
+ javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie("SomeCookie", str);
70
+
71
+ cookie.setSecure(true);
72
+ cookie.setHttpOnly(true);
73
+ cookie.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet
74
+ // e.g., /benchmark/sql-01/BenchmarkTest01001
75
+ response.addCookie(cookie);
76
+
77
+ response.getWriter()
78
+ .println(
79
+ "Created cookie: 'SomeCookie': with value: '"
80
+ + org.owasp.esapi.ESAPI.encoder().encodeForHTML(str)
81
+ + "' and secure flag set to: true");
82
+ }
83
+ }
OWASP DATASET/BenchmarkTest00017.java ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * OWASP Benchmark v1.2
3
+ *
4
+ * <p>This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For
5
+ * details, please see <a
6
+ * href="https://owasp.org/www-project-benchmark/">https://owasp.org/www-project-benchmark/</a>.
7
+ *
8
+ * <p>The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms
9
+ * of the GNU General Public License as published by the Free Software Foundation, version 2.
10
+ *
11
+ * <p>The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY
12
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13
+ * PURPOSE. See the GNU General Public License for more details.
14
+ *
15
+ * @author Dave Wichers
16
+ * @created 2015
17
+ */
18
+ package org.owasp.benchmark.testcode;
19
+
20
+ import java.io.IOException;
21
+ import javax.servlet.ServletException;
22
+ import javax.servlet.annotation.WebServlet;
23
+ import javax.servlet.http.HttpServlet;
24
+ import javax.servlet.http.HttpServletRequest;
25
+ import javax.servlet.http.HttpServletResponse;
26
+
27
+ @WebServlet(value = "/cmdi-00/BenchmarkTest00017")
28
+ public class BenchmarkTest00017 extends HttpServlet {
29
+
30
+ private static final long serialVersionUID = 1L;
31
+
32
+ @Override
33
+ public void doGet(HttpServletRequest request, HttpServletResponse response)
34
+ throws ServletException, IOException {
35
+ doPost(request, response);
36
+ }
37
+
38
+ @Override
39
+ public void doPost(HttpServletRequest request, HttpServletResponse response)
40
+ throws ServletException, IOException {
41
+ // some code
42
+ response.setContentType("text/html;charset=UTF-8");
43
+
44
+ String param = "";
45
+ java.util.Enumeration<String> headers = request.getHeaders("BenchmarkTest00017");
46
+
47
+ if (headers != null && headers.hasMoreElements()) {
48
+ param = headers.nextElement(); // just grab first element
49
+ }
50
+
51
+ // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters().
52
+ param = java.net.URLDecoder.decode(param, "UTF-8");
53
+
54
+ String cmd = "";
55
+ String osName = System.getProperty("os.name");
56
+ if (osName.indexOf("Windows") != -1) {
57
+ cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo");
58
+ }
59
+
60
+ Runtime r = Runtime.getRuntime();
61
+
62
+ try {
63
+ Process p = r.exec(cmd + param);
64
+ org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response);
65
+ } catch (IOException e) {
66
+ System.out.println("Problem executing cmdi - TestCase");
67
+ response.getWriter()
68
+ .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage()));
69
+ return;
70
+ }
71
+ }
72
+ }
OWASP DATASET/BenchmarkTest00018.java ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * OWASP Benchmark v1.2
3
+ *
4
+ * <p>This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For
5
+ * details, please see <a
6
+ * href="https://owasp.org/www-project-benchmark/">https://owasp.org/www-project-benchmark/</a>.
7
+ *
8
+ * <p>The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms
9
+ * of the GNU General Public License as published by the Free Software Foundation, version 2.
10
+ *
11
+ * <p>The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY
12
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13
+ * PURPOSE. See the GNU General Public License for more details.
14
+ *
15
+ * @author Dave Wichers
16
+ * @created 2015
17
+ */
18
+ package org.owasp.benchmark.testcode;
19
+
20
+ import java.io.IOException;
21
+ import javax.servlet.ServletException;
22
+ import javax.servlet.annotation.WebServlet;
23
+ import javax.servlet.http.HttpServlet;
24
+ import javax.servlet.http.HttpServletRequest;
25
+ import javax.servlet.http.HttpServletResponse;
26
+
27
+ @WebServlet(value = "/sqli-00/BenchmarkTest00018")
28
+ public class BenchmarkTest00018 extends HttpServlet {
29
+
30
+ private static final long serialVersionUID = 1L;
31
+
32
+ @Override
33
+ public void doGet(HttpServletRequest request, HttpServletResponse response)
34
+ throws ServletException, IOException {
35
+ doPost(request, response);
36
+ }
37
+
38
+ @Override
39
+ public void doPost(HttpServletRequest request, HttpServletResponse response)
40
+ throws ServletException, IOException {
41
+ // some code
42
+ response.setContentType("text/html;charset=UTF-8");
43
+
44
+ String param = "";
45
+ java.util.Enumeration<String> headers = request.getHeaders("BenchmarkTest00018");
46
+
47
+ if (headers != null && headers.hasMoreElements()) {
48
+ param = headers.nextElement(); // just grab first element
49
+ }
50
+
51
+ // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters().
52
+ param = java.net.URLDecoder.decode(param, "UTF-8");
53
+
54
+ String sql = "INSERT INTO users (username, password) VALUES ('foo','" + param + "')";
55
+
56
+ try {
57
+ java.sql.Statement statement =
58
+ org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement();
59
+ int count = statement.executeUpdate(sql);
60
+ org.owasp.benchmark.helpers.DatabaseHelper.outputUpdateComplete(sql, response);
61
+ } catch (java.sql.SQLException e) {
62
+ if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) {
63
+ response.getWriter().println("Error processing request.");
64
+ return;
65
+ } else throw new ServletException(e);
66
+ }
67
+ }
68
+ }
OWASP DATASET/BenchmarkTest00019.java ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * OWASP Benchmark v1.2
3
+ *
4
+ * <p>This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For
5
+ * details, please see <a
6
+ * href="https://owasp.org/www-project-benchmark/">https://owasp.org/www-project-benchmark/</a>.
7
+ *
8
+ * <p>The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms
9
+ * of the GNU General Public License as published by the Free Software Foundation, version 2.
10
+ *
11
+ * <p>The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY
12
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13
+ * PURPOSE. See the GNU General Public License for more details.
14
+ *
15
+ * @author Dave Wichers
16
+ * @created 2015
17
+ */
18
+ package org.owasp.benchmark.testcode;
19
+
20
+ import java.io.IOException;
21
+ import javax.servlet.ServletException;
22
+ import javax.servlet.annotation.WebServlet;
23
+ import javax.servlet.http.HttpServlet;
24
+ import javax.servlet.http.HttpServletRequest;
25
+ import javax.servlet.http.HttpServletResponse;
26
+
27
+ @WebServlet(value = "/crypto-00/BenchmarkTest00019")
28
+ public class BenchmarkTest00019 extends HttpServlet {
29
+
30
+ private static final long serialVersionUID = 1L;
31
+
32
+ @Override
33
+ public void doGet(HttpServletRequest request, HttpServletResponse response)
34
+ throws ServletException, IOException {
35
+ doPost(request, response);
36
+ }
37
+
38
+ @Override
39
+ public void doPost(HttpServletRequest request, HttpServletResponse response)
40
+ throws ServletException, IOException {
41
+ // some code
42
+ response.setContentType("text/html;charset=UTF-8");
43
+
44
+ java.io.InputStream param = request.getInputStream();
45
+
46
+ try {
47
+ java.util.Properties benchmarkprops = new java.util.Properties();
48
+ benchmarkprops.load(
49
+ this.getClass().getClassLoader().getResourceAsStream("benchmark.properties"));
50
+ String algorithm = benchmarkprops.getProperty("cryptoAlg1", "DESede/ECB/PKCS5Padding");
51
+ javax.crypto.Cipher c = javax.crypto.Cipher.getInstance(algorithm);
52
+
53
+ // Prepare the cipher to encrypt
54
+ javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey();
55
+ c.init(javax.crypto.Cipher.ENCRYPT_MODE, key);
56
+
57
+ // encrypt and store the results
58
+ byte[] input = {(byte) '?'};
59
+ Object inputParam = param;
60
+ if (inputParam instanceof String) input = ((String) inputParam).getBytes();
61
+ if (inputParam instanceof java.io.InputStream) {
62
+ byte[] strInput = new byte[1000];
63
+ int i = ((java.io.InputStream) inputParam).read(strInput);
64
+ if (i == -1) {
65
+ response.getWriter()
66
+ .println(
67
+ "This input source requires a POST, not a GET. Incompatible UI for the InputStream source.");
68
+ return;
69
+ }
70
+ input = java.util.Arrays.copyOf(strInput, i);
71
+ }
72
+ byte[] result = c.doFinal(input);
73
+
74
+ java.io.File fileTarget =
75
+ new java.io.File(
76
+ new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR),
77
+ "passwordFile.txt");
78
+ java.io.FileWriter fw =
79
+ new java.io.FileWriter(fileTarget, true); // the true will append the new data
80
+ fw.write(
81
+ "secret_value="
82
+ + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true)
83
+ + "\n");
84
+ fw.close();
85
+ response.getWriter()
86
+ .println(
87
+ "Sensitive value: '"
88
+ + org.owasp
89
+ .esapi
90
+ .ESAPI
91
+ .encoder()
92
+ .encodeForHTML(new String(input))
93
+ + "' encrypted and stored<br/>");
94
+
95
+ } catch (java.security.NoSuchAlgorithmException
96
+ | javax.crypto.NoSuchPaddingException
97
+ | javax.crypto.IllegalBlockSizeException
98
+ | javax.crypto.BadPaddingException
99
+ | java.security.InvalidKeyException e) {
100
+ response.getWriter()
101
+ .println(
102
+ "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case");
103
+ e.printStackTrace(response.getWriter());
104
+ throw new ServletException(e);
105
+ }
106
+ }
107
+ }
OWASP DATASET/BenchmarkTest00020.java ADDED
@@ -0,0 +1,151 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * OWASP Benchmark v1.2
3
+ *
4
+ * <p>This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For
5
+ * details, please see <a
6
+ * href="https://owasp.org/www-project-benchmark/">https://owasp.org/www-project-benchmark/</a>.
7
+ *
8
+ * <p>The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms
9
+ * of the GNU General Public License as published by the Free Software Foundation, version 2.
10
+ *
11
+ * <p>The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY
12
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13
+ * PURPOSE. See the GNU General Public License for more details.
14
+ *
15
+ * @author Dave Wichers
16
+ * @created 2015
17
+ */
18
+ package org.owasp.benchmark.testcode;
19
+
20
+ import java.io.IOException;
21
+ import javax.servlet.ServletException;
22
+ import javax.servlet.annotation.WebServlet;
23
+ import javax.servlet.http.HttpServlet;
24
+ import javax.servlet.http.HttpServletRequest;
25
+ import javax.servlet.http.HttpServletResponse;
26
+
27
+ @WebServlet(value = "/crypto-00/BenchmarkTest00020")
28
+ public class BenchmarkTest00020 extends HttpServlet {
29
+
30
+ private static final long serialVersionUID = 1L;
31
+
32
+ @Override
33
+ public void doGet(HttpServletRequest request, HttpServletResponse response)
34
+ throws ServletException, IOException {
35
+ doPost(request, response);
36
+ }
37
+
38
+ @Override
39
+ public void doPost(HttpServletRequest request, HttpServletResponse response)
40
+ throws ServletException, IOException {
41
+ // some code
42
+ response.setContentType("text/html;charset=UTF-8");
43
+
44
+ String param = request.getParameter("BenchmarkTest00020");
45
+ if (param == null) param = "";
46
+
47
+ // Code based on example from:
48
+ // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/
49
+ // 8-byte initialization vector
50
+ // byte[] iv = {
51
+ // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2,
52
+ // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033
53
+ // };
54
+ java.security.SecureRandom random = new java.security.SecureRandom();
55
+ byte[] iv = random.generateSeed(8); // DES requires 8 byte keys
56
+
57
+ try {
58
+ javax.crypto.Cipher c =
59
+ javax.crypto.Cipher.getInstance("DES/CBC/PKCS5Padding", "SunJCE");
60
+ // Prepare the cipher to encrypt
61
+ javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey();
62
+ java.security.spec.AlgorithmParameterSpec paramSpec =
63
+ new javax.crypto.spec.IvParameterSpec(iv);
64
+ c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec);
65
+
66
+ // encrypt and store the results
67
+ byte[] input = {(byte) '?'};
68
+ Object inputParam = param;
69
+ if (inputParam instanceof String) input = ((String) inputParam).getBytes();
70
+ if (inputParam instanceof java.io.InputStream) {
71
+ byte[] strInput = new byte[1000];
72
+ int i = ((java.io.InputStream) inputParam).read(strInput);
73
+ if (i == -1) {
74
+ response.getWriter()
75
+ .println(
76
+ "This input source requires a POST, not a GET. Incompatible UI for the InputStream source.");
77
+ return;
78
+ }
79
+ input = java.util.Arrays.copyOf(strInput, i);
80
+ }
81
+ byte[] result = c.doFinal(input);
82
+
83
+ java.io.File fileTarget =
84
+ new java.io.File(
85
+ new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR),
86
+ "passwordFile.txt");
87
+ java.io.FileWriter fw =
88
+ new java.io.FileWriter(fileTarget, true); // the true will append the new data
89
+ fw.write(
90
+ "secret_value="
91
+ + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true)
92
+ + "\n");
93
+ fw.close();
94
+ response.getWriter()
95
+ .println(
96
+ "Sensitive value: '"
97
+ + org.owasp
98
+ .esapi
99
+ .ESAPI
100
+ .encoder()
101
+ .encodeForHTML(new String(input))
102
+ + "' encrypted and stored<br/>");
103
+
104
+ } catch (java.security.NoSuchAlgorithmException e) {
105
+ response.getWriter()
106
+ .println(
107
+ "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case");
108
+ e.printStackTrace(response.getWriter());
109
+ throw new ServletException(e);
110
+ } catch (java.security.NoSuchProviderException e) {
111
+ response.getWriter()
112
+ .println(
113
+ "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case");
114
+ e.printStackTrace(response.getWriter());
115
+ throw new ServletException(e);
116
+ } catch (javax.crypto.NoSuchPaddingException e) {
117
+ response.getWriter()
118
+ .println(
119
+ "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case");
120
+ e.printStackTrace(response.getWriter());
121
+ throw new ServletException(e);
122
+ } catch (javax.crypto.IllegalBlockSizeException e) {
123
+ response.getWriter()
124
+ .println(
125
+ "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case");
126
+ e.printStackTrace(response.getWriter());
127
+ throw new ServletException(e);
128
+ } catch (javax.crypto.BadPaddingException e) {
129
+ response.getWriter()
130
+ .println(
131
+ "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case");
132
+ e.printStackTrace(response.getWriter());
133
+ throw new ServletException(e);
134
+ } catch (java.security.InvalidKeyException e) {
135
+ response.getWriter()
136
+ .println(
137
+ "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case");
138
+ e.printStackTrace(response.getWriter());
139
+ throw new ServletException(e);
140
+ } catch (java.security.InvalidAlgorithmParameterException e) {
141
+ response.getWriter()
142
+ .println(
143
+ "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case");
144
+ e.printStackTrace(response.getWriter());
145
+ throw new ServletException(e);
146
+ }
147
+ response.getWriter()
148
+ .println(
149
+ "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.lang.String) executed");
150
+ }
151
+ }
OWASP DATASET/BenchmarkTest00021.java ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * OWASP Benchmark v1.2
3
+ *
4
+ * <p>This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For
5
+ * details, please see <a
6
+ * href="https://owasp.org/www-project-benchmark/">https://owasp.org/www-project-benchmark/</a>.
7
+ *
8
+ * <p>The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms
9
+ * of the GNU General Public License as published by the Free Software Foundation, version 2.
10
+ *
11
+ * <p>The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY
12
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13
+ * PURPOSE. See the GNU General Public License for more details.
14
+ *
15
+ * @author Dave Wichers
16
+ * @created 2015
17
+ */
18
+ package org.owasp.benchmark.testcode;
19
+
20
+ import java.io.IOException;
21
+ import javax.servlet.ServletException;
22
+ import javax.servlet.annotation.WebServlet;
23
+ import javax.servlet.http.HttpServlet;
24
+ import javax.servlet.http.HttpServletRequest;
25
+ import javax.servlet.http.HttpServletResponse;
26
+
27
+ @WebServlet(value = "/ldapi-00/BenchmarkTest00021")
28
+ public class BenchmarkTest00021 extends HttpServlet {
29
+
30
+ private static final long serialVersionUID = 1L;
31
+
32
+ @Override
33
+ public void doGet(HttpServletRequest request, HttpServletResponse response)
34
+ throws ServletException, IOException {
35
+ doPost(request, response);
36
+ }
37
+
38
+ @Override
39
+ public void doPost(HttpServletRequest request, HttpServletResponse response)
40
+ throws ServletException, IOException {
41
+ // some code
42
+ response.setContentType("text/html;charset=UTF-8");
43
+
44
+ String param = request.getParameter("BenchmarkTest00021");
45
+ if (param == null) param = "";
46
+
47
+ org.owasp.benchmark.helpers.LDAPManager ads = new org.owasp.benchmark.helpers.LDAPManager();
48
+ try {
49
+ response.setContentType("text/html;charset=UTF-8");
50
+ javax.naming.directory.DirContext ctx = ads.getDirContext();
51
+ String base = "ou=users,ou=system";
52
+ javax.naming.directory.SearchControls sc = new javax.naming.directory.SearchControls();
53
+ sc.setSearchScope(javax.naming.directory.SearchControls.SUBTREE_SCOPE);
54
+ String filter = "(&(objectclass=person))(|(uid=" + param + ")(street={0}))";
55
+ Object[] filters = new Object[] {"The streetz 4 Ms bar"};
56
+ // System.out.println("Filter " + filter);
57
+ boolean found = false;
58
+ javax.naming.NamingEnumeration<javax.naming.directory.SearchResult> results =
59
+ ctx.search(base, filter, filters, sc);
60
+ while (results.hasMore()) {
61
+ javax.naming.directory.SearchResult sr =
62
+ (javax.naming.directory.SearchResult) results.next();
63
+ javax.naming.directory.Attributes attrs = sr.getAttributes();
64
+
65
+ javax.naming.directory.Attribute attr = attrs.get("uid");
66
+ javax.naming.directory.Attribute attr2 = attrs.get("street");
67
+ if (attr != null) {
68
+ response.getWriter()
69
+ .println(
70
+ "LDAP query results:<br>"
71
+ + "Record found with name "
72
+ + attr.get()
73
+ + "<br>"
74
+ + "Address: "
75
+ + attr2.get()
76
+ + "<br>");
77
+ // System.out.println("record found " + attr.get());
78
+ found = true;
79
+ }
80
+ }
81
+ if (!found) {
82
+ response.getWriter()
83
+ .println(
84
+ "LDAP query results: nothing found for query: "
85
+ + org.owasp.esapi.ESAPI.encoder().encodeForHTML(filter));
86
+ }
87
+ } catch (javax.naming.NamingException e) {
88
+ throw new ServletException(e);
89
+ } finally {
90
+ try {
91
+ ads.closeDirContext();
92
+ } catch (Exception e) {
93
+ throw new ServletException(e);
94
+ }
95
+ }
96
+ }
97
+ }
OWASP DATASET/BenchmarkTest00022.java ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * OWASP Benchmark v1.2
3
+ *
4
+ * <p>This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For
5
+ * details, please see <a
6
+ * href="https://owasp.org/www-project-benchmark/">https://owasp.org/www-project-benchmark/</a>.
7
+ *
8
+ * <p>The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms
9
+ * of the GNU General Public License as published by the Free Software Foundation, version 2.
10
+ *
11
+ * <p>The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY
12
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13
+ * PURPOSE. See the GNU General Public License for more details.
14
+ *
15
+ * @author Dave Wichers
16
+ * @created 2015
17
+ */
18
+ package org.owasp.benchmark.testcode;
19
+
20
+ import java.io.IOException;
21
+ import javax.servlet.ServletException;
22
+ import javax.servlet.annotation.WebServlet;
23
+ import javax.servlet.http.HttpServlet;
24
+ import javax.servlet.http.HttpServletRequest;
25
+ import javax.servlet.http.HttpServletResponse;
26
+
27
+ @WebServlet(value = "/hash-00/BenchmarkTest00022")
28
+ public class BenchmarkTest00022 extends HttpServlet {
29
+
30
+ private static final long serialVersionUID = 1L;
31
+
32
+ @Override
33
+ public void doGet(HttpServletRequest request, HttpServletResponse response)
34
+ throws ServletException, IOException {
35
+ doPost(request, response);
36
+ }
37
+
38
+ @Override
39
+ public void doPost(HttpServletRequest request, HttpServletResponse response)
40
+ throws ServletException, IOException {
41
+ // some code
42
+ response.setContentType("text/html;charset=UTF-8");
43
+
44
+ String param = request.getParameter("BenchmarkTest00022");
45
+ if (param == null) param = "";
46
+
47
+ try {
48
+ java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA-256");
49
+ byte[] input = {(byte) '?'};
50
+ Object inputParam = param;
51
+ if (inputParam instanceof String) input = ((String) inputParam).getBytes();
52
+ if (inputParam instanceof java.io.InputStream) {
53
+ byte[] strInput = new byte[1000];
54
+ int i = ((java.io.InputStream) inputParam).read(strInput);
55
+ if (i == -1) {
56
+ response.getWriter()
57
+ .println(
58
+ "This input source requires a POST, not a GET. Incompatible UI for the InputStream source.");
59
+ return;
60
+ }
61
+ input = java.util.Arrays.copyOf(strInput, i);
62
+ }
63
+ md.update(input);
64
+
65
+ byte[] result = md.digest();
66
+ java.io.File fileTarget =
67
+ new java.io.File(
68
+ new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR),
69
+ "passwordFile.txt");
70
+ java.io.FileWriter fw =
71
+ new java.io.FileWriter(fileTarget, true); // the true will append the new data
72
+ fw.write(
73
+ "hash_value="
74
+ + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true)
75
+ + "\n");
76
+ fw.close();
77
+ response.getWriter()
78
+ .println(
79
+ "Sensitive value '"
80
+ + org.owasp
81
+ .esapi
82
+ .ESAPI
83
+ .encoder()
84
+ .encodeForHTML(new String(input))
85
+ + "' hashed and stored<br/>");
86
+
87
+ } catch (java.security.NoSuchAlgorithmException e) {
88
+ System.out.println("Problem executing hash - TestCase");
89
+ throw new ServletException(e);
90
+ }
91
+
92
+ response.getWriter()
93
+ .println(
94
+ "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed");
95
+ }
96
+ }
OWASP DATASET/BenchmarkTest00023.java ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * OWASP Benchmark v1.2
3
+ *
4
+ * <p>This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For
5
+ * details, please see <a
6
+ * href="https://owasp.org/www-project-benchmark/">https://owasp.org/www-project-benchmark/</a>.
7
+ *
8
+ * <p>The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms
9
+ * of the GNU General Public License as published by the Free Software Foundation, version 2.
10
+ *
11
+ * <p>The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY
12
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13
+ * PURPOSE. See the GNU General Public License for more details.
14
+ *
15
+ * @author Dave Wichers
16
+ * @created 2015
17
+ */
18
+ package org.owasp.benchmark.testcode;
19
+
20
+ import java.io.IOException;
21
+ import javax.servlet.ServletException;
22
+ import javax.servlet.annotation.WebServlet;
23
+ import javax.servlet.http.HttpServlet;
24
+ import javax.servlet.http.HttpServletRequest;
25
+ import javax.servlet.http.HttpServletResponse;
26
+
27
+ @WebServlet(value = "/weakrand-00/BenchmarkTest00023")
28
+ public class BenchmarkTest00023 extends HttpServlet {
29
+
30
+ private static final long serialVersionUID = 1L;
31
+
32
+ @Override
33
+ public void doGet(HttpServletRequest request, HttpServletResponse response)
34
+ throws ServletException, IOException {
35
+ doPost(request, response);
36
+ }
37
+
38
+ @Override
39
+ public void doPost(HttpServletRequest request, HttpServletResponse response)
40
+ throws ServletException, IOException {
41
+ // some code
42
+ response.setContentType("text/html;charset=UTF-8");
43
+
44
+ String param = request.getParameter("BenchmarkTest00023");
45
+ if (param == null) param = "";
46
+
47
+ float rand = new java.util.Random().nextFloat();
48
+ String rememberMeKey = Float.toString(rand).substring(2); // Trim off the 0. at the front.
49
+
50
+ String user = "Floyd";
51
+ String fullClassName = this.getClass().getName();
52
+ String testCaseNumber =
53
+ fullClassName.substring(
54
+ fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length());
55
+ user += testCaseNumber;
56
+
57
+ String cookieName = "rememberMe" + testCaseNumber;
58
+
59
+ boolean foundUser = false;
60
+ javax.servlet.http.Cookie[] cookies = request.getCookies();
61
+ if (cookies != null) {
62
+ for (int i = 0; !foundUser && i < cookies.length; i++) {
63
+ javax.servlet.http.Cookie cookie = cookies[i];
64
+ if (cookieName.equals(cookie.getName())) {
65
+ if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) {
66
+ foundUser = true;
67
+ }
68
+ }
69
+ }
70
+ }
71
+
72
+ if (foundUser) {
73
+ response.getWriter().println("Welcome back: " + user + "<br/>");
74
+ } else {
75
+ javax.servlet.http.Cookie rememberMe =
76
+ new javax.servlet.http.Cookie(cookieName, rememberMeKey);
77
+ rememberMe.setSecure(true);
78
+ rememberMe.setHttpOnly(true);
79
+ rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost());
80
+ rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet
81
+ // e.g., /benchmark/sql-01/BenchmarkTest01001
82
+ request.getSession().setAttribute(cookieName, rememberMeKey);
83
+ response.addCookie(rememberMe);
84
+ response.getWriter()
85
+ .println(
86
+ user
87
+ + " has been remembered with cookie: "
88
+ + rememberMe.getName()
89
+ + " whose value is: "
90
+ + rememberMe.getValue()
91
+ + "<br/>");
92
+ }
93
+
94
+ response.getWriter().println("Weak Randomness Test java.util.Random.nextFloat() executed");
95
+ }
96
+ }
OWASP DATASET/BenchmarkTest00024.java ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * OWASP Benchmark v1.2
3
+ *
4
+ * <p>This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For
5
+ * details, please see <a
6
+ * href="https://owasp.org/www-project-benchmark/">https://owasp.org/www-project-benchmark/</a>.
7
+ *
8
+ * <p>The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms
9
+ * of the GNU General Public License as published by the Free Software Foundation, version 2.
10
+ *
11
+ * <p>The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY
12
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13
+ * PURPOSE. See the GNU General Public License for more details.
14
+ *
15
+ * @author Dave Wichers
16
+ * @created 2015
17
+ */
18
+ package org.owasp.benchmark.testcode;
19
+
20
+ import java.io.IOException;
21
+ import javax.servlet.ServletException;
22
+ import javax.servlet.annotation.WebServlet;
23
+ import javax.servlet.http.HttpServlet;
24
+ import javax.servlet.http.HttpServletRequest;
25
+ import javax.servlet.http.HttpServletResponse;
26
+
27
+ @WebServlet(value = "/sqli-00/BenchmarkTest00024")
28
+ public class BenchmarkTest00024 extends HttpServlet {
29
+
30
+ private static final long serialVersionUID = 1L;
31
+
32
+ @Override
33
+ public void doGet(HttpServletRequest request, HttpServletResponse response)
34
+ throws ServletException, IOException {
35
+ doPost(request, response);
36
+ }
37
+
38
+ @Override
39
+ public void doPost(HttpServletRequest request, HttpServletResponse response)
40
+ throws ServletException, IOException {
41
+ // some code
42
+ response.setContentType("text/html;charset=UTF-8");
43
+
44
+ String param = request.getParameter("BenchmarkTest00024");
45
+ if (param == null) param = "";
46
+
47
+ String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + param + "'";
48
+
49
+ try {
50
+ java.sql.Connection connection =
51
+ org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection();
52
+ java.sql.PreparedStatement statement =
53
+ connection.prepareStatement(
54
+ sql,
55
+ java.sql.ResultSet.TYPE_FORWARD_ONLY,
56
+ java.sql.ResultSet.CONCUR_READ_ONLY,
57
+ java.sql.ResultSet.CLOSE_CURSORS_AT_COMMIT);
58
+ statement.setString(1, "foo");
59
+ statement.execute();
60
+ org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response);
61
+ } catch (java.sql.SQLException e) {
62
+ if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) {
63
+ response.getWriter().println("Error processing request.");
64
+ return;
65
+ } else throw new ServletException(e);
66
+ }
67
+ }
68
+ }
OWASP DATASET/BenchmarkTest00025.java ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * OWASP Benchmark v1.2
3
+ *
4
+ * <p>This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For
5
+ * details, please see <a
6
+ * href="https://owasp.org/www-project-benchmark/">https://owasp.org/www-project-benchmark/</a>.
7
+ *
8
+ * <p>The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms
9
+ * of the GNU General Public License as published by the Free Software Foundation, version 2.
10
+ *
11
+ * <p>The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY
12
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13
+ * PURPOSE. See the GNU General Public License for more details.
14
+ *
15
+ * @author Dave Wichers
16
+ * @created 2015
17
+ */
18
+ package org.owasp.benchmark.testcode;
19
+
20
+ import java.io.IOException;
21
+ import javax.servlet.ServletException;
22
+ import javax.servlet.annotation.WebServlet;
23
+ import javax.servlet.http.HttpServlet;
24
+ import javax.servlet.http.HttpServletRequest;
25
+ import javax.servlet.http.HttpServletResponse;
26
+
27
+ @WebServlet(value = "/sqli-00/BenchmarkTest00025")
28
+ public class BenchmarkTest00025 extends HttpServlet {
29
+
30
+ private static final long serialVersionUID = 1L;
31
+
32
+ @Override
33
+ public void doGet(HttpServletRequest request, HttpServletResponse response)
34
+ throws ServletException, IOException {
35
+ doPost(request, response);
36
+ }
37
+
38
+ @Override
39
+ public void doPost(HttpServletRequest request, HttpServletResponse response)
40
+ throws ServletException, IOException {
41
+ // some code
42
+ response.setContentType("text/html;charset=UTF-8");
43
+
44
+ String param = request.getParameter("BenchmarkTest00025");
45
+ if (param == null) param = "";
46
+
47
+ String sql = "SELECT userid from USERS where USERNAME='foo' and PASSWORD='" + param + "'";
48
+ try {
49
+ // Long results =
50
+ // org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForLong(sql);
51
+ Long results =
52
+ org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForObject(
53
+ sql, Long.class);
54
+ response.getWriter().println("Your results are: " + String.valueOf(results));
55
+ } catch (org.springframework.dao.EmptyResultDataAccessException e) {
56
+ response.getWriter()
57
+ .println(
58
+ "No results returned for query: "
59
+ + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql));
60
+ } catch (org.springframework.dao.DataAccessException e) {
61
+ if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) {
62
+ response.getWriter().println("Error processing request.");
63
+ } else throw new ServletException(e);
64
+ }
65
+ }
66
+ }
OWASP DATASET/BenchmarkTest00026.java ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * OWASP Benchmark v1.2
3
+ *
4
+ * <p>This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For
5
+ * details, please see <a
6
+ * href="https://owasp.org/www-project-benchmark/">https://owasp.org/www-project-benchmark/</a>.
7
+ *
8
+ * <p>The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms
9
+ * of the GNU General Public License as published by the Free Software Foundation, version 2.
10
+ *
11
+ * <p>The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY
12
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13
+ * PURPOSE. See the GNU General Public License for more details.
14
+ *
15
+ * @author Dave Wichers
16
+ * @created 2015
17
+ */
18
+ package org.owasp.benchmark.testcode;
19
+
20
+ import java.io.IOException;
21
+ import javax.servlet.ServletException;
22
+ import javax.servlet.annotation.WebServlet;
23
+ import javax.servlet.http.HttpServlet;
24
+ import javax.servlet.http.HttpServletRequest;
25
+ import javax.servlet.http.HttpServletResponse;
26
+
27
+ @WebServlet(value = "/sqli-00/BenchmarkTest00026")
28
+ public class BenchmarkTest00026 extends HttpServlet {
29
+
30
+ private static final long serialVersionUID = 1L;
31
+
32
+ @Override
33
+ public void doGet(HttpServletRequest request, HttpServletResponse response)
34
+ throws ServletException, IOException {
35
+ doPost(request, response);
36
+ }
37
+
38
+ @Override
39
+ public void doPost(HttpServletRequest request, HttpServletResponse response)
40
+ throws ServletException, IOException {
41
+ // some code
42
+ response.setContentType("text/html;charset=UTF-8");
43
+
44
+ String param = request.getParameter("BenchmarkTest00026");
45
+ if (param == null) param = "";
46
+
47
+ String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + param + "'";
48
+ try {
49
+ org.springframework.jdbc.support.rowset.SqlRowSet results =
50
+ org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForRowSet(sql);
51
+ response.getWriter().println("Your results are: ");
52
+
53
+ // System.out.println("Your results are");
54
+ while (results.next()) {
55
+ response.getWriter()
56
+ .println(
57
+ org.owasp
58
+ .esapi
59
+ .ESAPI
60
+ .encoder()
61
+ .encodeForHTML(results.getString("USERNAME"))
62
+ + " ");
63
+ // System.out.println(results.getString("USERNAME"));
64
+ }
65
+ } catch (org.springframework.dao.EmptyResultDataAccessException e) {
66
+ response.getWriter()
67
+ .println(
68
+ "No results returned for query: "
69
+ + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql));
70
+ } catch (org.springframework.dao.DataAccessException e) {
71
+ if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) {
72
+ response.getWriter().println("Error processing request.");
73
+ } else throw new ServletException(e);
74
+ }
75
+ }
76
+ }
OWASP DATASET/BenchmarkTest00027.java ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * OWASP Benchmark v1.2
3
+ *
4
+ * <p>This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For
5
+ * details, please see <a
6
+ * href="https://owasp.org/www-project-benchmark/">https://owasp.org/www-project-benchmark/</a>.
7
+ *
8
+ * <p>The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms
9
+ * of the GNU General Public License as published by the Free Software Foundation, version 2.
10
+ *
11
+ * <p>The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY
12
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13
+ * PURPOSE. See the GNU General Public License for more details.
14
+ *
15
+ * @author Dave Wichers
16
+ * @created 2015
17
+ */
18
+ package org.owasp.benchmark.testcode;
19
+
20
+ import java.io.IOException;
21
+ import javax.servlet.ServletException;
22
+ import javax.servlet.annotation.WebServlet;
23
+ import javax.servlet.http.HttpServlet;
24
+ import javax.servlet.http.HttpServletRequest;
25
+ import javax.servlet.http.HttpServletResponse;
26
+
27
+ @WebServlet(value = "/sqli-00/BenchmarkTest00027")
28
+ public class BenchmarkTest00027 extends HttpServlet {
29
+
30
+ private static final long serialVersionUID = 1L;
31
+
32
+ @Override
33
+ public void doGet(HttpServletRequest request, HttpServletResponse response)
34
+ throws ServletException, IOException {
35
+ doPost(request, response);
36
+ }
37
+
38
+ @Override
39
+ public void doPost(HttpServletRequest request, HttpServletResponse response)
40
+ throws ServletException, IOException {
41
+ // some code
42
+ response.setContentType("text/html;charset=UTF-8");
43
+
44
+ String param = request.getParameter("BenchmarkTest00027");
45
+ if (param == null) param = "";
46
+
47
+ String sql = "INSERT INTO users (username, password) VALUES ('foo','" + param + "')";
48
+
49
+ try {
50
+ java.sql.Statement statement =
51
+ org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement();
52
+ int count = statement.executeUpdate(sql);
53
+ org.owasp.benchmark.helpers.DatabaseHelper.outputUpdateComplete(sql, response);
54
+ } catch (java.sql.SQLException e) {
55
+ if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) {
56
+ response.getWriter().println("Error processing request.");
57
+ return;
58
+ } else throw new ServletException(e);
59
+ }
60
+ }
61
+ }
OWASP DATASET/BenchmarkTest00028.java ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * OWASP Benchmark v1.2
3
+ *
4
+ * <p>This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For
5
+ * details, please see <a
6
+ * href="https://owasp.org/www-project-benchmark/">https://owasp.org/www-project-benchmark/</a>.
7
+ *
8
+ * <p>The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms
9
+ * of the GNU General Public License as published by the Free Software Foundation, version 2.
10
+ *
11
+ * <p>The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY
12
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13
+ * PURPOSE. See the GNU General Public License for more details.
14
+ *
15
+ * @author Dave Wichers
16
+ * @created 2015
17
+ */
18
+ package org.owasp.benchmark.testcode;
19
+
20
+ import java.io.IOException;
21
+ import javax.servlet.ServletException;
22
+ import javax.servlet.annotation.WebServlet;
23
+ import javax.servlet.http.HttpServlet;
24
+ import javax.servlet.http.HttpServletRequest;
25
+ import javax.servlet.http.HttpServletResponse;
26
+
27
+ @WebServlet(value = "/pathtraver-00/BenchmarkTest00028")
28
+ public class BenchmarkTest00028 extends HttpServlet {
29
+
30
+ private static final long serialVersionUID = 1L;
31
+
32
+ @Override
33
+ public void doGet(HttpServletRequest request, HttpServletResponse response)
34
+ throws ServletException, IOException {
35
+ doPost(request, response);
36
+ }
37
+
38
+ @Override
39
+ public void doPost(HttpServletRequest request, HttpServletResponse response)
40
+ throws ServletException, IOException {
41
+ // some code
42
+ response.setContentType("text/html;charset=UTF-8");
43
+
44
+ java.util.Map<String, String[]> map = request.getParameterMap();
45
+ String param = "";
46
+ if (!map.isEmpty()) {
47
+ String[] values = map.get("BenchmarkTest00028");
48
+ if (values != null) param = values[0];
49
+ }
50
+
51
+ String fileName = null;
52
+ java.io.FileOutputStream fos = null;
53
+
54
+ try {
55
+ fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + param;
56
+
57
+ fos = new java.io.FileOutputStream(fileName, false);
58
+ response.getWriter()
59
+ .println(
60
+ "Now ready to write to file: "
61
+ + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName));
62
+
63
+ } catch (Exception e) {
64
+ System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'");
65
+ // System.out.println("File exception caught and swallowed: " + e.getMessage());
66
+ } finally {
67
+ if (fos != null) {
68
+ try {
69
+ fos.close();
70
+ fos = null;
71
+ } catch (Exception e) {
72
+ // we tried...
73
+ }
74
+ }
75
+ }
76
+ }
77
+ }
OWASP DATASET/BenchmarkTest00029.java ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * OWASP Benchmark v1.2
3
+ *
4
+ * <p>This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For
5
+ * details, please see <a
6
+ * href="https://owasp.org/www-project-benchmark/">https://owasp.org/www-project-benchmark/</a>.
7
+ *
8
+ * <p>The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms
9
+ * of the GNU General Public License as published by the Free Software Foundation, version 2.
10
+ *
11
+ * <p>The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY
12
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13
+ * PURPOSE. See the GNU General Public License for more details.
14
+ *
15
+ * @author Dave Wichers
16
+ * @created 2015
17
+ */
18
+ package org.owasp.benchmark.testcode;
19
+
20
+ import java.io.IOException;
21
+ import javax.servlet.ServletException;
22
+ import javax.servlet.annotation.WebServlet;
23
+ import javax.servlet.http.HttpServlet;
24
+ import javax.servlet.http.HttpServletRequest;
25
+ import javax.servlet.http.HttpServletResponse;
26
+
27
+ @WebServlet(value = "/hash-00/BenchmarkTest00029")
28
+ public class BenchmarkTest00029 extends HttpServlet {
29
+
30
+ private static final long serialVersionUID = 1L;
31
+
32
+ @Override
33
+ public void doGet(HttpServletRequest request, HttpServletResponse response)
34
+ throws ServletException, IOException {
35
+ doPost(request, response);
36
+ }
37
+
38
+ @Override
39
+ public void doPost(HttpServletRequest request, HttpServletResponse response)
40
+ throws ServletException, IOException {
41
+ // some code
42
+ response.setContentType("text/html;charset=UTF-8");
43
+
44
+ java.util.Map<String, String[]> map = request.getParameterMap();
45
+ String param = "";
46
+ if (!map.isEmpty()) {
47
+ String[] values = map.get("BenchmarkTest00029");
48
+ if (values != null) param = values[0];
49
+ }
50
+
51
+ try {
52
+ java.util.Properties benchmarkprops = new java.util.Properties();
53
+ benchmarkprops.load(
54
+ this.getClass().getClassLoader().getResourceAsStream("benchmark.properties"));
55
+ String algorithm = benchmarkprops.getProperty("hashAlg1", "SHA512");
56
+ java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm);
57
+ byte[] input = {(byte) '?'};
58
+ Object inputParam = param;
59
+ if (inputParam instanceof String) input = ((String) inputParam).getBytes();
60
+ if (inputParam instanceof java.io.InputStream) {
61
+ byte[] strInput = new byte[1000];
62
+ int i = ((java.io.InputStream) inputParam).read(strInput);
63
+ if (i == -1) {
64
+ response.getWriter()
65
+ .println(
66
+ "This input source requires a POST, not a GET. Incompatible UI for the InputStream source.");
67
+ return;
68
+ }
69
+ input = java.util.Arrays.copyOf(strInput, i);
70
+ }
71
+ md.update(input);
72
+
73
+ byte[] result = md.digest();
74
+ java.io.File fileTarget =
75
+ new java.io.File(
76
+ new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR),
77
+ "passwordFile.txt");
78
+ java.io.FileWriter fw =
79
+ new java.io.FileWriter(fileTarget, true); // the true will append the new data
80
+ fw.write(
81
+ "hash_value="
82
+ + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true)
83
+ + "\n");
84
+ fw.close();
85
+ response.getWriter()
86
+ .println(
87
+ "Sensitive value '"
88
+ + org.owasp
89
+ .esapi
90
+ .ESAPI
91
+ .encoder()
92
+ .encodeForHTML(new String(input))
93
+ + "' hashed and stored<br/>");
94
+
95
+ } catch (java.security.NoSuchAlgorithmException e) {
96
+ System.out.println("Problem executing hash - TestCase");
97
+ throw new ServletException(e);
98
+ }
99
+
100
+ response.getWriter()
101
+ .println(
102
+ "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed");
103
+ }
104
+ }
OWASP DATASET/BenchmarkTest00030.java ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * OWASP Benchmark v1.2
3
+ *
4
+ * <p>This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For
5
+ * details, please see <a
6
+ * href="https://owasp.org/www-project-benchmark/">https://owasp.org/www-project-benchmark/</a>.
7
+ *
8
+ * <p>The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms
9
+ * of the GNU General Public License as published by the Free Software Foundation, version 2.
10
+ *
11
+ * <p>The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY
12
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13
+ * PURPOSE. See the GNU General Public License for more details.
14
+ *
15
+ * @author Dave Wichers
16
+ * @created 2015
17
+ */
18
+ package org.owasp.benchmark.testcode;
19
+
20
+ import java.io.IOException;
21
+ import javax.servlet.ServletException;
22
+ import javax.servlet.annotation.WebServlet;
23
+ import javax.servlet.http.HttpServlet;
24
+ import javax.servlet.http.HttpServletRequest;
25
+ import javax.servlet.http.HttpServletResponse;
26
+
27
+ @WebServlet(value = "/xss-00/BenchmarkTest00030")
28
+ public class BenchmarkTest00030 extends HttpServlet {
29
+
30
+ private static final long serialVersionUID = 1L;
31
+
32
+ @Override
33
+ public void doGet(HttpServletRequest request, HttpServletResponse response)
34
+ throws ServletException, IOException {
35
+ doPost(request, response);
36
+ }
37
+
38
+ @Override
39
+ public void doPost(HttpServletRequest request, HttpServletResponse response)
40
+ throws ServletException, IOException {
41
+ // some code
42
+ response.setContentType("text/html;charset=UTF-8");
43
+
44
+ java.util.Map<String, String[]> map = request.getParameterMap();
45
+ String param = "";
46
+ if (!map.isEmpty()) {
47
+ String[] values = map.get("BenchmarkTest00030");
48
+ if (values != null) param = values[0];
49
+ }
50
+
51
+ response.setHeader("X-XSS-Protection", "0");
52
+ Object[] obj = {"a", "b"};
53
+ response.getWriter().printf(param, obj);
54
+ }
55
+ }
OWASP DATASET/BenchmarkTest00031.java ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * OWASP Benchmark v1.2
3
+ *
4
+ * <p>This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For
5
+ * details, please see <a
6
+ * href="https://owasp.org/www-project-benchmark/">https://owasp.org/www-project-benchmark/</a>.
7
+ *
8
+ * <p>The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms
9
+ * of the GNU General Public License as published by the Free Software Foundation, version 2.
10
+ *
11
+ * <p>The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY
12
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13
+ * PURPOSE. See the GNU General Public License for more details.
14
+ *
15
+ * @author Dave Wichers
16
+ * @created 2015
17
+ */
18
+ package org.owasp.benchmark.testcode;
19
+
20
+ import java.io.IOException;
21
+ import javax.servlet.ServletException;
22
+ import javax.servlet.annotation.WebServlet;
23
+ import javax.servlet.http.HttpServlet;
24
+ import javax.servlet.http.HttpServletRequest;
25
+ import javax.servlet.http.HttpServletResponse;
26
+
27
+ @WebServlet(value = "/trustbound-00/BenchmarkTest00031")
28
+ public class BenchmarkTest00031 extends HttpServlet {
29
+
30
+ private static final long serialVersionUID = 1L;
31
+
32
+ @Override
33
+ public void doGet(HttpServletRequest request, HttpServletResponse response)
34
+ throws ServletException, IOException {
35
+ doPost(request, response);
36
+ }
37
+
38
+ @Override
39
+ public void doPost(HttpServletRequest request, HttpServletResponse response)
40
+ throws ServletException, IOException {
41
+ // some code
42
+ response.setContentType("text/html;charset=UTF-8");
43
+
44
+ java.util.Map<String, String[]> map = request.getParameterMap();
45
+ String param = "";
46
+ if (!map.isEmpty()) {
47
+ String[] values = map.get("BenchmarkTest00031");
48
+ if (values != null) param = values[0];
49
+ }
50
+
51
+ // javax.servlet.http.HttpSession.putValue(java.lang.String,java.lang.Object^)
52
+ request.getSession().putValue("userid", param);
53
+
54
+ response.getWriter()
55
+ .println(
56
+ "Item: 'userid' with value: '"
57
+ + org.owasp.benchmark.helpers.Utils.encodeForHTML(param)
58
+ + "' saved in session.");
59
+ }
60
+ }
OWASP DATASET/BenchmarkTest00032.java ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * OWASP Benchmark v1.2
3
+ *
4
+ * <p>This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For
5
+ * details, please see <a
6
+ * href="https://owasp.org/www-project-benchmark/">https://owasp.org/www-project-benchmark/</a>.
7
+ *
8
+ * <p>The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms
9
+ * of the GNU General Public License as published by the Free Software Foundation, version 2.
10
+ *
11
+ * <p>The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY
12
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13
+ * PURPOSE. See the GNU General Public License for more details.
14
+ *
15
+ * @author Dave Wichers
16
+ * @created 2015
17
+ */
18
+ package org.owasp.benchmark.testcode;
19
+
20
+ import java.io.IOException;
21
+ import javax.servlet.ServletException;
22
+ import javax.servlet.annotation.WebServlet;
23
+ import javax.servlet.http.HttpServlet;
24
+ import javax.servlet.http.HttpServletRequest;
25
+ import javax.servlet.http.HttpServletResponse;
26
+
27
+ @WebServlet(value = "/sqli-00/BenchmarkTest00032")
28
+ public class BenchmarkTest00032 extends HttpServlet {
29
+
30
+ private static final long serialVersionUID = 1L;
31
+
32
+ @Override
33
+ public void doGet(HttpServletRequest request, HttpServletResponse response)
34
+ throws ServletException, IOException {
35
+ doPost(request, response);
36
+ }
37
+
38
+ @Override
39
+ public void doPost(HttpServletRequest request, HttpServletResponse response)
40
+ throws ServletException, IOException {
41
+ // some code
42
+ response.setContentType("text/html;charset=UTF-8");
43
+
44
+ java.util.Map<String, String[]> map = request.getParameterMap();
45
+ String param = "";
46
+ if (!map.isEmpty()) {
47
+ String[] values = map.get("BenchmarkTest00032");
48
+ if (values != null) param = values[0];
49
+ }
50
+
51
+ try {
52
+ String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + param + "'";
53
+
54
+ org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.execute(sql);
55
+ response.getWriter()
56
+ .println(
57
+ "No results can be displayed for query: "
58
+ + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)
59
+ + "<br>"
60
+ + " because the Spring execute method doesn't return results.");
61
+
62
+ } catch (org.springframework.dao.DataAccessException e) {
63
+ if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) {
64
+ response.getWriter().println("Error processing request.");
65
+ } else throw new ServletException(e);
66
+ }
67
+ }
68
+ }
OWASP DATASET/BenchmarkTest00033.java ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * OWASP Benchmark v1.2
3
+ *
4
+ * <p>This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For
5
+ * details, please see <a
6
+ * href="https://owasp.org/www-project-benchmark/">https://owasp.org/www-project-benchmark/</a>.
7
+ *
8
+ * <p>The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms
9
+ * of the GNU General Public License as published by the Free Software Foundation, version 2.
10
+ *
11
+ * <p>The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY
12
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13
+ * PURPOSE. See the GNU General Public License for more details.
14
+ *
15
+ * @author Dave Wichers
16
+ * @created 2015
17
+ */
18
+ package org.owasp.benchmark.testcode;
19
+
20
+ import java.io.IOException;
21
+ import javax.servlet.ServletException;
22
+ import javax.servlet.annotation.WebServlet;
23
+ import javax.servlet.http.HttpServlet;
24
+ import javax.servlet.http.HttpServletRequest;
25
+ import javax.servlet.http.HttpServletResponse;
26
+
27
+ @WebServlet(value = "/sqli-00/BenchmarkTest00033")
28
+ public class BenchmarkTest00033 extends HttpServlet {
29
+
30
+ private static final long serialVersionUID = 1L;
31
+
32
+ @Override
33
+ public void doGet(HttpServletRequest request, HttpServletResponse response)
34
+ throws ServletException, IOException {
35
+ doPost(request, response);
36
+ }
37
+
38
+ @Override
39
+ public void doPost(HttpServletRequest request, HttpServletResponse response)
40
+ throws ServletException, IOException {
41
+ // some code
42
+ response.setContentType("text/html;charset=UTF-8");
43
+
44
+ java.util.Map<String, String[]> map = request.getParameterMap();
45
+ String param = "";
46
+ if (!map.isEmpty()) {
47
+ String[] values = map.get("BenchmarkTest00033");
48
+ if (values != null) param = values[0];
49
+ }
50
+
51
+ String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + param + "'";
52
+ try {
53
+ org.springframework.jdbc.support.rowset.SqlRowSet results =
54
+ org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForRowSet(sql);
55
+ response.getWriter().println("Your results are: ");
56
+
57
+ // System.out.println("Your results are");
58
+ while (results.next()) {
59
+ response.getWriter()
60
+ .println(
61
+ org.owasp
62
+ .esapi
63
+ .ESAPI
64
+ .encoder()
65
+ .encodeForHTML(results.getString("USERNAME"))
66
+ + " ");
67
+ // System.out.println(results.getString("USERNAME"));
68
+ }
69
+ } catch (org.springframework.dao.EmptyResultDataAccessException e) {
70
+ response.getWriter()
71
+ .println(
72
+ "No results returned for query: "
73
+ + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql));
74
+ } catch (org.springframework.dao.DataAccessException e) {
75
+ if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) {
76
+ response.getWriter().println("Error processing request.");
77
+ } else throw new ServletException(e);
78
+ }
79
+ }
80
+ }
OWASP DATASET/BenchmarkTest00034.java ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * OWASP Benchmark v1.2
3
+ *
4
+ * <p>This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For
5
+ * details, please see <a
6
+ * href="https://owasp.org/www-project-benchmark/">https://owasp.org/www-project-benchmark/</a>.
7
+ *
8
+ * <p>The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms
9
+ * of the GNU General Public License as published by the Free Software Foundation, version 2.
10
+ *
11
+ * <p>The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY
12
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13
+ * PURPOSE. See the GNU General Public License for more details.
14
+ *
15
+ * @author Dave Wichers
16
+ * @created 2015
17
+ */
18
+ package org.owasp.benchmark.testcode;
19
+
20
+ import java.io.IOException;
21
+ import javax.servlet.ServletException;
22
+ import javax.servlet.annotation.WebServlet;
23
+ import javax.servlet.http.HttpServlet;
24
+ import javax.servlet.http.HttpServletRequest;
25
+ import javax.servlet.http.HttpServletResponse;
26
+
27
+ @WebServlet(value = "/sqli-00/BenchmarkTest00034")
28
+ public class BenchmarkTest00034 extends HttpServlet {
29
+
30
+ private static final long serialVersionUID = 1L;
31
+
32
+ @Override
33
+ public void doGet(HttpServletRequest request, HttpServletResponse response)
34
+ throws ServletException, IOException {
35
+ doPost(request, response);
36
+ }
37
+
38
+ @Override
39
+ public void doPost(HttpServletRequest request, HttpServletResponse response)
40
+ throws ServletException, IOException {
41
+ // some code
42
+ response.setContentType("text/html;charset=UTF-8");
43
+
44
+ java.util.Map<String, String[]> map = request.getParameterMap();
45
+ String param = "";
46
+ if (!map.isEmpty()) {
47
+ String[] values = map.get("BenchmarkTest00034");
48
+ if (values != null) param = values[0];
49
+ }
50
+
51
+ String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + param + "'";
52
+
53
+ try {
54
+ java.sql.Statement statement =
55
+ org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement();
56
+ statement.execute(sql, java.sql.Statement.RETURN_GENERATED_KEYS);
57
+ org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response);
58
+ } catch (java.sql.SQLException e) {
59
+ if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) {
60
+ response.getWriter().println("Error processing request.");
61
+ return;
62
+ } else throw new ServletException(e);
63
+ }
64
+ }
65
+ }
OWASP DATASET/BenchmarkTest00035.java ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * OWASP Benchmark v1.2
3
+ *
4
+ * <p>This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For
5
+ * details, please see <a
6
+ * href="https://owasp.org/www-project-benchmark/">https://owasp.org/www-project-benchmark/</a>.
7
+ *
8
+ * <p>The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms
9
+ * of the GNU General Public License as published by the Free Software Foundation, version 2.
10
+ *
11
+ * <p>The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY
12
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13
+ * PURPOSE. See the GNU General Public License for more details.
14
+ *
15
+ * @author Dave Wichers
16
+ * @created 2015
17
+ */
18
+ package org.owasp.benchmark.testcode;
19
+
20
+ import java.io.IOException;
21
+ import javax.servlet.ServletException;
22
+ import javax.servlet.annotation.WebServlet;
23
+ import javax.servlet.http.HttpServlet;
24
+ import javax.servlet.http.HttpServletRequest;
25
+ import javax.servlet.http.HttpServletResponse;
26
+
27
+ @WebServlet(value = "/crypto-00/BenchmarkTest00035")
28
+ public class BenchmarkTest00035 extends HttpServlet {
29
+
30
+ private static final long serialVersionUID = 1L;
31
+
32
+ @Override
33
+ public void doGet(HttpServletRequest request, HttpServletResponse response)
34
+ throws ServletException, IOException {
35
+ doPost(request, response);
36
+ }
37
+
38
+ @Override
39
+ public void doPost(HttpServletRequest request, HttpServletResponse response)
40
+ throws ServletException, IOException {
41
+ // some code
42
+ response.setContentType("text/html;charset=UTF-8");
43
+
44
+ String param = "";
45
+ boolean flag = true;
46
+ java.util.Enumeration<String> names = request.getParameterNames();
47
+ while (names.hasMoreElements() && flag) {
48
+ String name = (String) names.nextElement();
49
+ String[] values = request.getParameterValues(name);
50
+ if (values != null) {
51
+ for (int i = 0; i < values.length && flag; i++) {
52
+ String value = values[i];
53
+ if (value.equals("BenchmarkTest00035")) {
54
+ param = name;
55
+ flag = false;
56
+ }
57
+ }
58
+ }
59
+ }
60
+
61
+ try {
62
+ java.util.Properties benchmarkprops = new java.util.Properties();
63
+ benchmarkprops.load(
64
+ this.getClass().getClassLoader().getResourceAsStream("benchmark.properties"));
65
+ String algorithm = benchmarkprops.getProperty("cryptoAlg1", "DESede/ECB/PKCS5Padding");
66
+ javax.crypto.Cipher c = javax.crypto.Cipher.getInstance(algorithm);
67
+
68
+ // Prepare the cipher to encrypt
69
+ javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey();
70
+ c.init(javax.crypto.Cipher.ENCRYPT_MODE, key);
71
+
72
+ // encrypt and store the results
73
+ byte[] input = {(byte) '?'};
74
+ Object inputParam = param;
75
+ if (inputParam instanceof String) input = ((String) inputParam).getBytes();
76
+ if (inputParam instanceof java.io.InputStream) {
77
+ byte[] strInput = new byte[1000];
78
+ int i = ((java.io.InputStream) inputParam).read(strInput);
79
+ if (i == -1) {
80
+ response.getWriter()
81
+ .println(
82
+ "This input source requires a POST, not a GET. Incompatible UI for the InputStream source.");
83
+ return;
84
+ }
85
+ input = java.util.Arrays.copyOf(strInput, i);
86
+ }
87
+ byte[] result = c.doFinal(input);
88
+
89
+ java.io.File fileTarget =
90
+ new java.io.File(
91
+ new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR),
92
+ "passwordFile.txt");
93
+ java.io.FileWriter fw =
94
+ new java.io.FileWriter(fileTarget, true); // the true will append the new data
95
+ fw.write(
96
+ "secret_value="
97
+ + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true)
98
+ + "\n");
99
+ fw.close();
100
+ response.getWriter()
101
+ .println(
102
+ "Sensitive value: '"
103
+ + org.owasp
104
+ .esapi
105
+ .ESAPI
106
+ .encoder()
107
+ .encodeForHTML(new String(input))
108
+ + "' encrypted and stored<br/>");
109
+
110
+ } catch (java.security.NoSuchAlgorithmException
111
+ | javax.crypto.NoSuchPaddingException
112
+ | javax.crypto.IllegalBlockSizeException
113
+ | javax.crypto.BadPaddingException
114
+ | java.security.InvalidKeyException e) {
115
+ response.getWriter()
116
+ .println(
117
+ "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case");
118
+ e.printStackTrace(response.getWriter());
119
+ throw new ServletException(e);
120
+ }
121
+ }
122
+ }
OWASP DATASET/BenchmarkTest00036.java ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * OWASP Benchmark v1.2
3
+ *
4
+ * <p>This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For
5
+ * details, please see <a
6
+ * href="https://owasp.org/www-project-benchmark/">https://owasp.org/www-project-benchmark/</a>.
7
+ *
8
+ * <p>The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms
9
+ * of the GNU General Public License as published by the Free Software Foundation, version 2.
10
+ *
11
+ * <p>The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY
12
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13
+ * PURPOSE. See the GNU General Public License for more details.
14
+ *
15
+ * @author Dave Wichers
16
+ * @created 2015
17
+ */
18
+ package org.owasp.benchmark.testcode;
19
+
20
+ import java.io.IOException;
21
+ import javax.servlet.ServletException;
22
+ import javax.servlet.annotation.WebServlet;
23
+ import javax.servlet.http.HttpServlet;
24
+ import javax.servlet.http.HttpServletRequest;
25
+ import javax.servlet.http.HttpServletResponse;
26
+
27
+ @WebServlet(value = "/xss-00/BenchmarkTest00036")
28
+ public class BenchmarkTest00036 extends HttpServlet {
29
+
30
+ private static final long serialVersionUID = 1L;
31
+
32
+ @Override
33
+ public void doGet(HttpServletRequest request, HttpServletResponse response)
34
+ throws ServletException, IOException {
35
+ doPost(request, response);
36
+ }
37
+
38
+ @Override
39
+ public void doPost(HttpServletRequest request, HttpServletResponse response)
40
+ throws ServletException, IOException {
41
+ // some code
42
+ response.setContentType("text/html;charset=UTF-8");
43
+
44
+ String param = "";
45
+ boolean flag = true;
46
+ java.util.Enumeration<String> names = request.getParameterNames();
47
+ while (names.hasMoreElements() && flag) {
48
+ String name = (String) names.nextElement();
49
+ String[] values = request.getParameterValues(name);
50
+ if (values != null) {
51
+ for (int i = 0; i < values.length && flag; i++) {
52
+ String value = values[i];
53
+ if (value.equals("BenchmarkTest00036")) {
54
+ param = name;
55
+ flag = false;
56
+ }
57
+ }
58
+ }
59
+ }
60
+
61
+ response.setHeader("X-XSS-Protection", "0");
62
+ int length = 1;
63
+ if (param != null) {
64
+ length = param.length();
65
+ response.getWriter().write(param.toCharArray(), 0, length);
66
+ }
67
+ }
68
+ }
OWASP DATASET/BenchmarkTest00037.java ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * OWASP Benchmark v1.2
3
+ *
4
+ * <p>This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For
5
+ * details, please see <a
6
+ * href="https://owasp.org/www-project-benchmark/">https://owasp.org/www-project-benchmark/</a>.
7
+ *
8
+ * <p>The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms
9
+ * of the GNU General Public License as published by the Free Software Foundation, version 2.
10
+ *
11
+ * <p>The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY
12
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13
+ * PURPOSE. See the GNU General Public License for more details.
14
+ *
15
+ * @author Dave Wichers
16
+ * @created 2015
17
+ */
18
+ package org.owasp.benchmark.testcode;
19
+
20
+ import java.io.IOException;
21
+ import javax.servlet.ServletException;
22
+ import javax.servlet.annotation.WebServlet;
23
+ import javax.servlet.http.HttpServlet;
24
+ import javax.servlet.http.HttpServletRequest;
25
+ import javax.servlet.http.HttpServletResponse;
26
+
27
+ @WebServlet(value = "/sqli-00/BenchmarkTest00037")
28
+ public class BenchmarkTest00037 extends HttpServlet {
29
+
30
+ private static final long serialVersionUID = 1L;
31
+
32
+ @Override
33
+ public void doGet(HttpServletRequest request, HttpServletResponse response)
34
+ throws ServletException, IOException {
35
+ doPost(request, response);
36
+ }
37
+
38
+ @Override
39
+ public void doPost(HttpServletRequest request, HttpServletResponse response)
40
+ throws ServletException, IOException {
41
+ // some code
42
+ response.setContentType("text/html;charset=UTF-8");
43
+
44
+ String param = "";
45
+ boolean flag = true;
46
+ java.util.Enumeration<String> names = request.getParameterNames();
47
+ while (names.hasMoreElements() && flag) {
48
+ String name = (String) names.nextElement();
49
+ String[] values = request.getParameterValues(name);
50
+ if (values != null) {
51
+ for (int i = 0; i < values.length && flag; i++) {
52
+ String value = values[i];
53
+ if (value.equals("BenchmarkTest00037")) {
54
+ param = name;
55
+ flag = false;
56
+ }
57
+ }
58
+ }
59
+ }
60
+
61
+ String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + param + "'";
62
+
63
+ try {
64
+ java.sql.Connection connection =
65
+ org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection();
66
+ java.sql.PreparedStatement statement =
67
+ connection.prepareStatement(
68
+ sql,
69
+ java.sql.ResultSet.TYPE_FORWARD_ONLY,
70
+ java.sql.ResultSet.CONCUR_READ_ONLY,
71
+ java.sql.ResultSet.CLOSE_CURSORS_AT_COMMIT);
72
+ statement.setString(1, "foo");
73
+ statement.execute();
74
+ org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response);
75
+ } catch (java.sql.SQLException e) {
76
+ if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) {
77
+ response.getWriter().println("Error processing request.");
78
+ return;
79
+ } else throw new ServletException(e);
80
+ }
81
+ }
82
+ }
OWASP DATASET/BenchmarkTest00038.java ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * OWASP Benchmark v1.2
3
+ *
4
+ * <p>This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For
5
+ * details, please see <a
6
+ * href="https://owasp.org/www-project-benchmark/">https://owasp.org/www-project-benchmark/</a>.
7
+ *
8
+ * <p>The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms
9
+ * of the GNU General Public License as published by the Free Software Foundation, version 2.
10
+ *
11
+ * <p>The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY
12
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13
+ * PURPOSE. See the GNU General Public License for more details.
14
+ *
15
+ * @author Dave Wichers
16
+ * @created 2015
17
+ */
18
+ package org.owasp.benchmark.testcode;
19
+
20
+ import java.io.IOException;
21
+ import javax.servlet.ServletException;
22
+ import javax.servlet.annotation.WebServlet;
23
+ import javax.servlet.http.HttpServlet;
24
+ import javax.servlet.http.HttpServletRequest;
25
+ import javax.servlet.http.HttpServletResponse;
26
+
27
+ @WebServlet(value = "/sqli-00/BenchmarkTest00038")
28
+ public class BenchmarkTest00038 extends HttpServlet {
29
+
30
+ private static final long serialVersionUID = 1L;
31
+
32
+ @Override
33
+ public void doGet(HttpServletRequest request, HttpServletResponse response)
34
+ throws ServletException, IOException {
35
+ doPost(request, response);
36
+ }
37
+
38
+ @Override
39
+ public void doPost(HttpServletRequest request, HttpServletResponse response)
40
+ throws ServletException, IOException {
41
+ // some code
42
+ response.setContentType("text/html;charset=UTF-8");
43
+
44
+ String param = "";
45
+ boolean flag = true;
46
+ java.util.Enumeration<String> names = request.getParameterNames();
47
+ while (names.hasMoreElements() && flag) {
48
+ String name = (String) names.nextElement();
49
+ String[] values = request.getParameterValues(name);
50
+ if (values != null) {
51
+ for (int i = 0; i < values.length && flag; i++) {
52
+ String value = values[i];
53
+ if (value.equals("BenchmarkTest00038")) {
54
+ param = name;
55
+ flag = false;
56
+ }
57
+ }
58
+ }
59
+ }
60
+
61
+ String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + param + "'";
62
+ try {
63
+ java.util.List<String> results =
64
+ org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.query(
65
+ sql,
66
+ new org.springframework.jdbc.core.RowMapper<String>() {
67
+ @Override
68
+ public String mapRow(java.sql.ResultSet rs, int rowNum)
69
+ throws java.sql.SQLException {
70
+ try {
71
+ return rs.getString("USERNAME");
72
+ } catch (java.sql.SQLException e) {
73
+ if (org.owasp.benchmark.helpers.DatabaseHelper
74
+ .hideSQLErrors) {
75
+ return "Error processing query.";
76
+ } else throw e;
77
+ }
78
+ }
79
+ });
80
+ response.getWriter().println("Your results are: ");
81
+
82
+ for (String s : results) {
83
+ response.getWriter()
84
+ .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(s) + "<br>");
85
+ }
86
+ } catch (org.springframework.dao.EmptyResultDataAccessException e) {
87
+ response.getWriter()
88
+ .println(
89
+ "No results returned for query: "
90
+ + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql));
91
+ } catch (org.springframework.dao.DataAccessException e) {
92
+ if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) {
93
+ response.getWriter().println("Error processing request.");
94
+ } else throw new ServletException(e);
95
+ }
96
+ }
97
+ }
OWASP DATASET/BenchmarkTest00039.java ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * OWASP Benchmark v1.2
3
+ *
4
+ * <p>This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For
5
+ * details, please see <a
6
+ * href="https://owasp.org/www-project-benchmark/">https://owasp.org/www-project-benchmark/</a>.
7
+ *
8
+ * <p>The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms
9
+ * of the GNU General Public License as published by the Free Software Foundation, version 2.
10
+ *
11
+ * <p>The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY
12
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13
+ * PURPOSE. See the GNU General Public License for more details.
14
+ *
15
+ * @author Dave Wichers
16
+ * @created 2015
17
+ */
18
+ package org.owasp.benchmark.testcode;
19
+
20
+ import java.io.IOException;
21
+ import javax.servlet.ServletException;
22
+ import javax.servlet.annotation.WebServlet;
23
+ import javax.servlet.http.HttpServlet;
24
+ import javax.servlet.http.HttpServletRequest;
25
+ import javax.servlet.http.HttpServletResponse;
26
+
27
+ @WebServlet(value = "/sqli-00/BenchmarkTest00039")
28
+ public class BenchmarkTest00039 extends HttpServlet {
29
+
30
+ private static final long serialVersionUID = 1L;
31
+
32
+ @Override
33
+ public void doGet(HttpServletRequest request, HttpServletResponse response)
34
+ throws ServletException, IOException {
35
+ doPost(request, response);
36
+ }
37
+
38
+ @Override
39
+ public void doPost(HttpServletRequest request, HttpServletResponse response)
40
+ throws ServletException, IOException {
41
+ // some code
42
+ response.setContentType("text/html;charset=UTF-8");
43
+
44
+ String param = "";
45
+ boolean flag = true;
46
+ java.util.Enumeration<String> names = request.getParameterNames();
47
+ while (names.hasMoreElements() && flag) {
48
+ String name = (String) names.nextElement();
49
+ String[] values = request.getParameterValues(name);
50
+ if (values != null) {
51
+ for (int i = 0; i < values.length && flag; i++) {
52
+ String value = values[i];
53
+ if (value.equals("BenchmarkTest00039")) {
54
+ param = name;
55
+ flag = false;
56
+ }
57
+ }
58
+ }
59
+ }
60
+
61
+ String sql =
62
+ "SELECT TOP 1 userid from USERS where USERNAME='foo' and PASSWORD='" + param + "'";
63
+ try {
64
+ java.util.Map<String, Object> results =
65
+ org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForMap(sql);
66
+ response.getWriter().println("Your results are: ");
67
+
68
+ // System.out.println("Your results are");
69
+ response.getWriter()
70
+ .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(results.toString()));
71
+ // System.out.println(results.toString());
72
+ } catch (org.springframework.dao.EmptyResultDataAccessException e) {
73
+ response.getWriter()
74
+ .println(
75
+ "No results returned for query: "
76
+ + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql));
77
+ } catch (org.springframework.dao.DataAccessException e) {
78
+ if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) {
79
+ response.getWriter().println("Error processing request.");
80
+ } else throw new ServletException(e);
81
+ }
82
+ }
83
+ }
OWASP DATASET/BenchmarkTest00040.java ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * OWASP Benchmark v1.2
3
+ *
4
+ * <p>This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For
5
+ * details, please see <a
6
+ * href="https://owasp.org/www-project-benchmark/">https://owasp.org/www-project-benchmark/</a>.
7
+ *
8
+ * <p>The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms
9
+ * of the GNU General Public License as published by the Free Software Foundation, version 2.
10
+ *
11
+ * <p>The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY
12
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13
+ * PURPOSE. See the GNU General Public License for more details.
14
+ *
15
+ * @author Dave Wichers
16
+ * @created 2015
17
+ */
18
+ package org.owasp.benchmark.testcode;
19
+
20
+ import java.io.IOException;
21
+ import javax.servlet.ServletException;
22
+ import javax.servlet.annotation.WebServlet;
23
+ import javax.servlet.http.HttpServlet;
24
+ import javax.servlet.http.HttpServletRequest;
25
+ import javax.servlet.http.HttpServletResponse;
26
+
27
+ @WebServlet(value = "/pathtraver-00/BenchmarkTest00040")
28
+ public class BenchmarkTest00040 extends HttpServlet {
29
+
30
+ private static final long serialVersionUID = 1L;
31
+
32
+ @Override
33
+ public void doGet(HttpServletRequest request, HttpServletResponse response)
34
+ throws ServletException, IOException {
35
+ doPost(request, response);
36
+ }
37
+
38
+ @Override
39
+ public void doPost(HttpServletRequest request, HttpServletResponse response)
40
+ throws ServletException, IOException {
41
+ // some code
42
+ response.setContentType("text/html;charset=UTF-8");
43
+
44
+ org.owasp.benchmark.helpers.SeparateClassRequest scr =
45
+ new org.owasp.benchmark.helpers.SeparateClassRequest(request);
46
+ String param = scr.getTheParameter("BenchmarkTest00040");
47
+ if (param == null) param = "";
48
+
49
+ java.io.File fileTarget = new java.io.File(param);
50
+ response.getWriter()
51
+ .println(
52
+ "Access to file: '"
53
+ + org.owasp
54
+ .esapi
55
+ .ESAPI
56
+ .encoder()
57
+ .encodeForHTML(fileTarget.toString())
58
+ + "' created.");
59
+ if (fileTarget.exists()) {
60
+ response.getWriter().println(" And file already exists.");
61
+ } else {
62
+ response.getWriter().println(" But file doesn't exist yet.");
63
+ }
64
+ }
65
+ }
OWASP DATASET/BenchmarkTest00041.java ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * OWASP Benchmark v1.2
3
+ *
4
+ * <p>This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For
5
+ * details, please see <a
6
+ * href="https://owasp.org/www-project-benchmark/">https://owasp.org/www-project-benchmark/</a>.
7
+ *
8
+ * <p>The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms
9
+ * of the GNU General Public License as published by the Free Software Foundation, version 2.
10
+ *
11
+ * <p>The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY
12
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13
+ * PURPOSE. See the GNU General Public License for more details.
14
+ *
15
+ * @author Dave Wichers
16
+ * @created 2015
17
+ */
18
+ package org.owasp.benchmark.testcode;
19
+
20
+ import java.io.IOException;
21
+ import javax.servlet.ServletException;
22
+ import javax.servlet.annotation.WebServlet;
23
+ import javax.servlet.http.HttpServlet;
24
+ import javax.servlet.http.HttpServletRequest;
25
+ import javax.servlet.http.HttpServletResponse;
26
+
27
+ @WebServlet(value = "/xss-00/BenchmarkTest00041")
28
+ public class BenchmarkTest00041 extends HttpServlet {
29
+
30
+ private static final long serialVersionUID = 1L;
31
+
32
+ @Override
33
+ public void doGet(HttpServletRequest request, HttpServletResponse response)
34
+ throws ServletException, IOException {
35
+ doPost(request, response);
36
+ }
37
+
38
+ @Override
39
+ public void doPost(HttpServletRequest request, HttpServletResponse response)
40
+ throws ServletException, IOException {
41
+ // some code
42
+ response.setContentType("text/html;charset=UTF-8");
43
+
44
+ org.owasp.benchmark.helpers.SeparateClassRequest scr =
45
+ new org.owasp.benchmark.helpers.SeparateClassRequest(request);
46
+ String param = scr.getTheParameter("BenchmarkTest00041");
47
+ if (param == null) param = "";
48
+
49
+ response.setHeader("X-XSS-Protection", "0");
50
+ int length = 1;
51
+ if (param != null) {
52
+ length = param.length();
53
+ response.getWriter().write(param, 0, length);
54
+ }
55
+ }
56
+ }
OWASP DATASET/BenchmarkTest00042.java ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * OWASP Benchmark v1.2
3
+ *
4
+ * <p>This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For
5
+ * details, please see <a
6
+ * href="https://owasp.org/www-project-benchmark/">https://owasp.org/www-project-benchmark/</a>.
7
+ *
8
+ * <p>The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms
9
+ * of the GNU General Public License as published by the Free Software Foundation, version 2.
10
+ *
11
+ * <p>The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY
12
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13
+ * PURPOSE. See the GNU General Public License for more details.
14
+ *
15
+ * @author Dave Wichers
16
+ * @created 2015
17
+ */
18
+ package org.owasp.benchmark.testcode;
19
+
20
+ import java.io.IOException;
21
+ import javax.servlet.ServletException;
22
+ import javax.servlet.annotation.WebServlet;
23
+ import javax.servlet.http.HttpServlet;
24
+ import javax.servlet.http.HttpServletRequest;
25
+ import javax.servlet.http.HttpServletResponse;
26
+
27
+ @WebServlet(value = "/weakrand-00/BenchmarkTest00042")
28
+ public class BenchmarkTest00042 extends HttpServlet {
29
+
30
+ private static final long serialVersionUID = 1L;
31
+
32
+ @Override
33
+ public void doGet(HttpServletRequest request, HttpServletResponse response)
34
+ throws ServletException, IOException {
35
+ doPost(request, response);
36
+ }
37
+
38
+ @Override
39
+ public void doPost(HttpServletRequest request, HttpServletResponse response)
40
+ throws ServletException, IOException {
41
+ // some code
42
+ response.setContentType("text/html;charset=UTF-8");
43
+
44
+ org.owasp.benchmark.helpers.SeparateClassRequest scr =
45
+ new org.owasp.benchmark.helpers.SeparateClassRequest(request);
46
+ String param = scr.getTheParameter("BenchmarkTest00042");
47
+ if (param == null) param = "";
48
+
49
+ try {
50
+ int r = java.security.SecureRandom.getInstance("SHA1PRNG").nextInt();
51
+ String rememberMeKey = Integer.toString(r);
52
+
53
+ String user = "SafeIngrid";
54
+ String fullClassName = this.getClass().getName();
55
+ String testCaseNumber =
56
+ fullClassName.substring(
57
+ fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length());
58
+ user += testCaseNumber;
59
+
60
+ String cookieName = "rememberMe" + testCaseNumber;
61
+
62
+ boolean foundUser = false;
63
+ javax.servlet.http.Cookie[] cookies = request.getCookies();
64
+ if (cookies != null) {
65
+ for (int i = 0; !foundUser && i < cookies.length; i++) {
66
+ javax.servlet.http.Cookie cookie = cookies[i];
67
+ if (cookieName.equals(cookie.getName())) {
68
+ if (cookie.getValue()
69
+ .equals(request.getSession().getAttribute(cookieName))) {
70
+ foundUser = true;
71
+ }
72
+ }
73
+ }
74
+ }
75
+
76
+ if (foundUser) {
77
+ response.getWriter().println("Welcome back: " + user + "<br/>");
78
+ } else {
79
+ javax.servlet.http.Cookie rememberMe =
80
+ new javax.servlet.http.Cookie(cookieName, rememberMeKey);
81
+ rememberMe.setSecure(true);
82
+ rememberMe.setHttpOnly(true);
83
+ rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet
84
+ // e.g., /benchmark/sql-01/BenchmarkTest01001
85
+ request.getSession().setAttribute(cookieName, rememberMeKey);
86
+ response.addCookie(rememberMe);
87
+ response.getWriter()
88
+ .println(
89
+ user
90
+ + " has been remembered with cookie: "
91
+ + rememberMe.getName()
92
+ + " whose value is: "
93
+ + rememberMe.getValue()
94
+ + "<br/>");
95
+ }
96
+ } catch (java.security.NoSuchAlgorithmException e) {
97
+ System.out.println("Problem executing SecureRandom.nextInt() - TestCase");
98
+ throw new ServletException(e);
99
+ }
100
+ response.getWriter()
101
+ .println("Weak Randomness Test java.security.SecureRandom.nextInt() executed");
102
+ }
103
+ }
OWASP DATASET/BenchmarkTest00043.java ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * OWASP Benchmark v1.2
3
+ *
4
+ * <p>This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For
5
+ * details, please see <a
6
+ * href="https://owasp.org/www-project-benchmark/">https://owasp.org/www-project-benchmark/</a>.
7
+ *
8
+ * <p>The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms
9
+ * of the GNU General Public License as published by the Free Software Foundation, version 2.
10
+ *
11
+ * <p>The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY
12
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13
+ * PURPOSE. See the GNU General Public License for more details.
14
+ *
15
+ * @author Dave Wichers
16
+ * @created 2015
17
+ */
18
+ package org.owasp.benchmark.testcode;
19
+
20
+ import java.io.IOException;
21
+ import javax.servlet.ServletException;
22
+ import javax.servlet.annotation.WebServlet;
23
+ import javax.servlet.http.HttpServlet;
24
+ import javax.servlet.http.HttpServletRequest;
25
+ import javax.servlet.http.HttpServletResponse;
26
+
27
+ @WebServlet(value = "/sqli-00/BenchmarkTest00043")
28
+ public class BenchmarkTest00043 extends HttpServlet {
29
+
30
+ private static final long serialVersionUID = 1L;
31
+
32
+ @Override
33
+ public void doGet(HttpServletRequest request, HttpServletResponse response)
34
+ throws ServletException, IOException {
35
+ doPost(request, response);
36
+ }
37
+
38
+ @Override
39
+ public void doPost(HttpServletRequest request, HttpServletResponse response)
40
+ throws ServletException, IOException {
41
+ // some code
42
+ response.setContentType("text/html;charset=UTF-8");
43
+
44
+ org.owasp.benchmark.helpers.SeparateClassRequest scr =
45
+ new org.owasp.benchmark.helpers.SeparateClassRequest(request);
46
+ String param = scr.getTheParameter("BenchmarkTest00043");
47
+ if (param == null) param = "";
48
+
49
+ String sql = "INSERT INTO users (username, password) VALUES ('foo','" + param + "')";
50
+
51
+ try {
52
+ java.sql.Statement statement =
53
+ org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement();
54
+ int count = statement.executeUpdate(sql, new int[] {1, 2});
55
+ org.owasp.benchmark.helpers.DatabaseHelper.outputUpdateComplete(sql, response);
56
+ } catch (java.sql.SQLException e) {
57
+ if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) {
58
+ response.getWriter().println("Error processing request.");
59
+ return;
60
+ } else throw new ServletException(e);
61
+ }
62
+ }
63
+ }
OWASP DATASET/BenchmarkTest00044.java ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * OWASP Benchmark v1.2
3
+ *
4
+ * <p>This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For
5
+ * details, please see <a
6
+ * href="https://owasp.org/www-project-benchmark/">https://owasp.org/www-project-benchmark/</a>.
7
+ *
8
+ * <p>The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms
9
+ * of the GNU General Public License as published by the Free Software Foundation, version 2.
10
+ *
11
+ * <p>The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY
12
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13
+ * PURPOSE. See the GNU General Public License for more details.
14
+ *
15
+ * @author Dave Wichers
16
+ * @created 2015
17
+ */
18
+ package org.owasp.benchmark.testcode;
19
+
20
+ import java.io.IOException;
21
+ import javax.servlet.ServletException;
22
+ import javax.servlet.annotation.WebServlet;
23
+ import javax.servlet.http.HttpServlet;
24
+ import javax.servlet.http.HttpServletRequest;
25
+ import javax.servlet.http.HttpServletResponse;
26
+
27
+ @WebServlet(value = "/ldapi-00/BenchmarkTest00044")
28
+ public class BenchmarkTest00044 extends HttpServlet {
29
+
30
+ private static final long serialVersionUID = 1L;
31
+
32
+ @Override
33
+ public void doGet(HttpServletRequest request, HttpServletResponse response)
34
+ throws ServletException, IOException {
35
+ doPost(request, response);
36
+ }
37
+
38
+ @Override
39
+ public void doPost(HttpServletRequest request, HttpServletResponse response)
40
+ throws ServletException, IOException {
41
+ // some code
42
+ response.setContentType("text/html;charset=UTF-8");
43
+
44
+ String[] values = request.getParameterValues("BenchmarkTest00044");
45
+ String param;
46
+ if (values != null && values.length > 0) param = values[0];
47
+ else param = "";
48
+
49
+ org.owasp.benchmark.helpers.LDAPManager ads = new org.owasp.benchmark.helpers.LDAPManager();
50
+ try {
51
+ response.setContentType("text/html;charset=UTF-8");
52
+ javax.naming.directory.DirContext ctx = ads.getDirContext();
53
+ String base = "ou=users,ou=system";
54
+ javax.naming.directory.SearchControls sc = new javax.naming.directory.SearchControls();
55
+ sc.setSearchScope(javax.naming.directory.SearchControls.SUBTREE_SCOPE);
56
+ String filter = "(&(objectclass=person)(uid=" + param + "))";
57
+ // System.out.println("Filter " + filter);
58
+ boolean found = false;
59
+ javax.naming.NamingEnumeration<javax.naming.directory.SearchResult> results =
60
+ ctx.search(base, filter, sc);
61
+ while (results.hasMore()) {
62
+ javax.naming.directory.SearchResult sr =
63
+ (javax.naming.directory.SearchResult) results.next();
64
+ javax.naming.directory.Attributes attrs = sr.getAttributes();
65
+
66
+ javax.naming.directory.Attribute attr = attrs.get("uid");
67
+ javax.naming.directory.Attribute attr2 = attrs.get("street");
68
+ if (attr != null) {
69
+ response.getWriter()
70
+ .println(
71
+ "LDAP query results:<br>"
72
+ + "Record found with name "
73
+ + attr.get()
74
+ + "<br>"
75
+ + "Address: "
76
+ + attr2.get()
77
+ + "<br>");
78
+ // System.out.println("record found " + attr.get());
79
+ found = true;
80
+ }
81
+ }
82
+ if (!found) {
83
+ response.getWriter()
84
+ .println(
85
+ "LDAP query results: nothing found for query: "
86
+ + org.owasp.esapi.ESAPI.encoder().encodeForHTML(filter));
87
+ }
88
+ } catch (javax.naming.NamingException e) {
89
+ throw new ServletException(e);
90
+ } finally {
91
+ try {
92
+ ads.closeDirContext();
93
+ } catch (Exception e) {
94
+ throw new ServletException(e);
95
+ }
96
+ }
97
+ }
98
+ }
OWASP DATASET/BenchmarkTest00045.java ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * OWASP Benchmark v1.2
3
+ *
4
+ * <p>This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For
5
+ * details, please see <a
6
+ * href="https://owasp.org/www-project-benchmark/">https://owasp.org/www-project-benchmark/</a>.
7
+ *
8
+ * <p>The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms
9
+ * of the GNU General Public License as published by the Free Software Foundation, version 2.
10
+ *
11
+ * <p>The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY
12
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13
+ * PURPOSE. See the GNU General Public License for more details.
14
+ *
15
+ * @author Dave Wichers
16
+ * @created 2015
17
+ */
18
+ package org.owasp.benchmark.testcode;
19
+
20
+ import java.io.IOException;
21
+ import javax.servlet.ServletException;
22
+ import javax.servlet.annotation.WebServlet;
23
+ import javax.servlet.http.HttpServlet;
24
+ import javax.servlet.http.HttpServletRequest;
25
+ import javax.servlet.http.HttpServletResponse;
26
+
27
+ @WebServlet(value = "/pathtraver-00/BenchmarkTest00045")
28
+ public class BenchmarkTest00045 extends HttpServlet {
29
+
30
+ private static final long serialVersionUID = 1L;
31
+
32
+ @Override
33
+ public void doGet(HttpServletRequest request, HttpServletResponse response)
34
+ throws ServletException, IOException {
35
+ doPost(request, response);
36
+ }
37
+
38
+ @Override
39
+ public void doPost(HttpServletRequest request, HttpServletResponse response)
40
+ throws ServletException, IOException {
41
+ // some code
42
+ response.setContentType("text/html;charset=UTF-8");
43
+
44
+ String[] values = request.getParameterValues("BenchmarkTest00045");
45
+ String param;
46
+ if (values != null && values.length > 0) param = values[0];
47
+ else param = "";
48
+
49
+ String fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + param;
50
+
51
+ try (
52
+ // Create the file first so the test won't throw an exception if it doesn't exist.
53
+ // Note: Don't actually do this because this method signature could cause a tool to find
54
+ // THIS file constructor
55
+ // as a vuln, rather than the File signature we are trying to actually test.
56
+ // If necessary, just run the benchmark twice. The 1st run should create all the necessary
57
+ // files.
58
+ // new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR +
59
+ // param).createNewFile();
60
+
61
+ java.io.FileOutputStream fos =
62
+ new java.io.FileOutputStream(new java.io.FileInputStream(fileName).getFD()); ) {
63
+ response.getWriter()
64
+ .println(
65
+ "Now ready to write to file: "
66
+ + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName));
67
+
68
+ } catch (Exception e) {
69
+ System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'");
70
+ }
71
+ }
72
+ }
OWASP DATASET/BenchmarkTest00046.java ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * OWASP Benchmark v1.2
3
+ *
4
+ * <p>This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For
5
+ * details, please see <a
6
+ * href="https://owasp.org/www-project-benchmark/">https://owasp.org/www-project-benchmark/</a>.
7
+ *
8
+ * <p>The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms
9
+ * of the GNU General Public License as published by the Free Software Foundation, version 2.
10
+ *
11
+ * <p>The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY
12
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13
+ * PURPOSE. See the GNU General Public License for more details.
14
+ *
15
+ * @author Dave Wichers
16
+ * @created 2015
17
+ */
18
+ package org.owasp.benchmark.testcode;
19
+
20
+ import java.io.IOException;
21
+ import javax.servlet.ServletException;
22
+ import javax.servlet.annotation.WebServlet;
23
+ import javax.servlet.http.HttpServlet;
24
+ import javax.servlet.http.HttpServletRequest;
25
+ import javax.servlet.http.HttpServletResponse;
26
+
27
+ @WebServlet(value = "/hash-00/BenchmarkTest00046")
28
+ public class BenchmarkTest00046 extends HttpServlet {
29
+
30
+ private static final long serialVersionUID = 1L;
31
+
32
+ @Override
33
+ public void doGet(HttpServletRequest request, HttpServletResponse response)
34
+ throws ServletException, IOException {
35
+ doPost(request, response);
36
+ }
37
+
38
+ @Override
39
+ public void doPost(HttpServletRequest request, HttpServletResponse response)
40
+ throws ServletException, IOException {
41
+ // some code
42
+ response.setContentType("text/html;charset=UTF-8");
43
+
44
+ String[] values = request.getParameterValues("BenchmarkTest00046");
45
+ String param;
46
+ if (values != null && values.length > 0) param = values[0];
47
+ else param = "";
48
+
49
+ try {
50
+ java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5");
51
+ byte[] input = {(byte) '?'};
52
+ Object inputParam = param;
53
+ if (inputParam instanceof String) input = ((String) inputParam).getBytes();
54
+ if (inputParam instanceof java.io.InputStream) {
55
+ byte[] strInput = new byte[1000];
56
+ int i = ((java.io.InputStream) inputParam).read(strInput);
57
+ if (i == -1) {
58
+ response.getWriter()
59
+ .println(
60
+ "This input source requires a POST, not a GET. Incompatible UI for the InputStream source.");
61
+ return;
62
+ }
63
+ input = java.util.Arrays.copyOf(strInput, i);
64
+ }
65
+ md.update(input);
66
+
67
+ byte[] result = md.digest();
68
+ java.io.File fileTarget =
69
+ new java.io.File(
70
+ new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR),
71
+ "passwordFile.txt");
72
+ java.io.FileWriter fw =
73
+ new java.io.FileWriter(fileTarget, true); // the true will append the new data
74
+ fw.write(
75
+ "hash_value="
76
+ + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true)
77
+ + "\n");
78
+ fw.close();
79
+ response.getWriter()
80
+ .println(
81
+ "Sensitive value '"
82
+ + org.owasp
83
+ .esapi
84
+ .ESAPI
85
+ .encoder()
86
+ .encodeForHTML(new String(input))
87
+ + "' hashed and stored<br/>");
88
+
89
+ } catch (java.security.NoSuchAlgorithmException e) {
90
+ System.out.println("Problem executing hash - TestCase");
91
+ throw new ServletException(e);
92
+ }
93
+
94
+ response.getWriter()
95
+ .println(
96
+ "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed");
97
+ }
98
+ }
OWASP DATASET/BenchmarkTest00047.java ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * OWASP Benchmark v1.2
3
+ *
4
+ * <p>This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For
5
+ * details, please see <a
6
+ * href="https://owasp.org/www-project-benchmark/">https://owasp.org/www-project-benchmark/</a>.
7
+ *
8
+ * <p>The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms
9
+ * of the GNU General Public License as published by the Free Software Foundation, version 2.
10
+ *
11
+ * <p>The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY
12
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13
+ * PURPOSE. See the GNU General Public License for more details.
14
+ *
15
+ * @author Dave Wichers
16
+ * @created 2015
17
+ */
18
+ package org.owasp.benchmark.testcode;
19
+
20
+ import java.io.IOException;
21
+ import javax.servlet.ServletException;
22
+ import javax.servlet.annotation.WebServlet;
23
+ import javax.servlet.http.HttpServlet;
24
+ import javax.servlet.http.HttpServletRequest;
25
+ import javax.servlet.http.HttpServletResponse;
26
+
27
+ @WebServlet(value = "/xss-00/BenchmarkTest00047")
28
+ public class BenchmarkTest00047 extends HttpServlet {
29
+
30
+ private static final long serialVersionUID = 1L;
31
+
32
+ @Override
33
+ public void doGet(HttpServletRequest request, HttpServletResponse response)
34
+ throws ServletException, IOException {
35
+ doPost(request, response);
36
+ }
37
+
38
+ @Override
39
+ public void doPost(HttpServletRequest request, HttpServletResponse response)
40
+ throws ServletException, IOException {
41
+ // some code
42
+ response.setContentType("text/html;charset=UTF-8");
43
+
44
+ String queryString = request.getQueryString();
45
+ String paramval = "BenchmarkTest00047" + "=";
46
+ int paramLoc = -1;
47
+ if (queryString != null) paramLoc = queryString.indexOf(paramval);
48
+ if (paramLoc == -1) {
49
+ response.getWriter()
50
+ .println(
51
+ "getQueryString() couldn't find expected parameter '"
52
+ + "BenchmarkTest00047"
53
+ + "' in query string.");
54
+ return;
55
+ }
56
+
57
+ String param =
58
+ queryString.substring(
59
+ paramLoc
60
+ + paramval
61
+ .length()); // 1st assume "BenchmarkTest00047" param is last
62
+ // parameter in query string.
63
+ // And then check to see if its in the middle of the query string and if so, trim off what
64
+ // comes after.
65
+ int ampersandLoc = queryString.indexOf("&", paramLoc);
66
+ if (ampersandLoc != -1) {
67
+ param = queryString.substring(paramLoc + paramval.length(), ampersandLoc);
68
+ }
69
+ param = java.net.URLDecoder.decode(param, "UTF-8");
70
+
71
+ response.setHeader("X-XSS-Protection", "0");
72
+ Object[] obj = {"a", "b"};
73
+ response.getWriter().format(param, obj);
74
+ }
75
+ }
OWASP DATASET/BenchmarkTest00048.java ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * OWASP Benchmark v1.2
3
+ *
4
+ * <p>This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For
5
+ * details, please see <a
6
+ * href="https://owasp.org/www-project-benchmark/">https://owasp.org/www-project-benchmark/</a>.
7
+ *
8
+ * <p>The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms
9
+ * of the GNU General Public License as published by the Free Software Foundation, version 2.
10
+ *
11
+ * <p>The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY
12
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13
+ * PURPOSE. See the GNU General Public License for more details.
14
+ *
15
+ * @author Dave Wichers
16
+ * @created 2015
17
+ */
18
+ package org.owasp.benchmark.testcode;
19
+
20
+ import java.io.IOException;
21
+ import javax.servlet.ServletException;
22
+ import javax.servlet.annotation.WebServlet;
23
+ import javax.servlet.http.HttpServlet;
24
+ import javax.servlet.http.HttpServletRequest;
25
+ import javax.servlet.http.HttpServletResponse;
26
+
27
+ @WebServlet(value = "/xss-00/BenchmarkTest00048")
28
+ public class BenchmarkTest00048 extends HttpServlet {
29
+
30
+ private static final long serialVersionUID = 1L;
31
+
32
+ @Override
33
+ public void doGet(HttpServletRequest request, HttpServletResponse response)
34
+ throws ServletException, IOException {
35
+ doPost(request, response);
36
+ }
37
+
38
+ @Override
39
+ public void doPost(HttpServletRequest request, HttpServletResponse response)
40
+ throws ServletException, IOException {
41
+ // some code
42
+ response.setContentType("text/html;charset=UTF-8");
43
+
44
+ String queryString = request.getQueryString();
45
+ String paramval = "BenchmarkTest00048" + "=";
46
+ int paramLoc = -1;
47
+ if (queryString != null) paramLoc = queryString.indexOf(paramval);
48
+ if (paramLoc == -1) {
49
+ response.getWriter()
50
+ .println(
51
+ "getQueryString() couldn't find expected parameter '"
52
+ + "BenchmarkTest00048"
53
+ + "' in query string.");
54
+ return;
55
+ }
56
+
57
+ String param =
58
+ queryString.substring(
59
+ paramLoc
60
+ + paramval
61
+ .length()); // 1st assume "BenchmarkTest00048" param is last
62
+ // parameter in query string.
63
+ // And then check to see if its in the middle of the query string and if so, trim off what
64
+ // comes after.
65
+ int ampersandLoc = queryString.indexOf("&", paramLoc);
66
+ if (ampersandLoc != -1) {
67
+ param = queryString.substring(paramLoc + paramval.length(), ampersandLoc);
68
+ }
69
+ param = java.net.URLDecoder.decode(param, "UTF-8");
70
+
71
+ response.setHeader("X-XSS-Protection", "0");
72
+ response.getWriter().print(param.toCharArray());
73
+ }
74
+ }
OWASP DATASET/BenchmarkTest00049.java ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * OWASP Benchmark v1.2
3
+ *
4
+ * <p>This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For
5
+ * details, please see <a
6
+ * href="https://owasp.org/www-project-benchmark/">https://owasp.org/www-project-benchmark/</a>.
7
+ *
8
+ * <p>The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms
9
+ * of the GNU General Public License as published by the Free Software Foundation, version 2.
10
+ *
11
+ * <p>The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY
12
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13
+ * PURPOSE. See the GNU General Public License for more details.
14
+ *
15
+ * @author Dave Wichers
16
+ * @created 2015
17
+ */
18
+ package org.owasp.benchmark.testcode;
19
+
20
+ import java.io.IOException;
21
+ import javax.servlet.ServletException;
22
+ import javax.servlet.annotation.WebServlet;
23
+ import javax.servlet.http.HttpServlet;
24
+ import javax.servlet.http.HttpServletRequest;
25
+ import javax.servlet.http.HttpServletResponse;
26
+
27
+ @WebServlet(value = "/xss-00/BenchmarkTest00049")
28
+ public class BenchmarkTest00049 extends HttpServlet {
29
+
30
+ private static final long serialVersionUID = 1L;
31
+
32
+ @Override
33
+ public void doGet(HttpServletRequest request, HttpServletResponse response)
34
+ throws ServletException, IOException {
35
+ doPost(request, response);
36
+ }
37
+
38
+ @Override
39
+ public void doPost(HttpServletRequest request, HttpServletResponse response)
40
+ throws ServletException, IOException {
41
+ // some code
42
+ response.setContentType("text/html;charset=UTF-8");
43
+
44
+ String queryString = request.getQueryString();
45
+ String paramval = "BenchmarkTest00049" + "=";
46
+ int paramLoc = -1;
47
+ if (queryString != null) paramLoc = queryString.indexOf(paramval);
48
+ if (paramLoc == -1) {
49
+ response.getWriter()
50
+ .println(
51
+ "getQueryString() couldn't find expected parameter '"
52
+ + "BenchmarkTest00049"
53
+ + "' in query string.");
54
+ return;
55
+ }
56
+
57
+ String param =
58
+ queryString.substring(
59
+ paramLoc
60
+ + paramval
61
+ .length()); // 1st assume "BenchmarkTest00049" param is last
62
+ // parameter in query string.
63
+ // And then check to see if its in the middle of the query string and if so, trim off what
64
+ // comes after.
65
+ int ampersandLoc = queryString.indexOf("&", paramLoc);
66
+ if (ampersandLoc != -1) {
67
+ param = queryString.substring(paramLoc + paramval.length(), ampersandLoc);
68
+ }
69
+ param = java.net.URLDecoder.decode(param, "UTF-8");
70
+
71
+ response.setHeader("X-XSS-Protection", "0");
72
+ response.getWriter().write("Parameter value: " + param);
73
+ }
74
+ }
OWASP DATASET/BenchmarkTest00050.java ADDED
@@ -0,0 +1,152 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * OWASP Benchmark v1.2
3
+ *
4
+ * <p>This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For
5
+ * details, please see <a
6
+ * href="https://owasp.org/www-project-benchmark/">https://owasp.org/www-project-benchmark/</a>.
7
+ *
8
+ * <p>The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms
9
+ * of the GNU General Public License as published by the Free Software Foundation, version 2.
10
+ *
11
+ * <p>The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY
12
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13
+ * PURPOSE. See the GNU General Public License for more details.
14
+ *
15
+ * @author Dave Wichers
16
+ * @created 2015
17
+ */
18
+ package org.owasp.benchmark.testcode;
19
+
20
+ import java.io.IOException;
21
+ import javax.servlet.ServletException;
22
+ import javax.servlet.annotation.WebServlet;
23
+ import javax.servlet.http.HttpServlet;
24
+ import javax.servlet.http.HttpServletRequest;
25
+ import javax.servlet.http.HttpServletResponse;
26
+
27
+ @WebServlet(value = "/crypto-00/BenchmarkTest00050")
28
+ public class BenchmarkTest00050 extends HttpServlet {
29
+
30
+ private static final long serialVersionUID = 1L;
31
+
32
+ @Override
33
+ public void doGet(HttpServletRequest request, HttpServletResponse response)
34
+ throws ServletException, IOException {
35
+ doPost(request, response);
36
+ }
37
+
38
+ @Override
39
+ public void doPost(HttpServletRequest request, HttpServletResponse response)
40
+ throws ServletException, IOException {
41
+ // some code
42
+ response.setContentType("text/html;charset=UTF-8");
43
+
44
+ org.owasp.benchmark.helpers.SeparateClassRequest scr =
45
+ new org.owasp.benchmark.helpers.SeparateClassRequest(request);
46
+ String param = scr.getTheValue("BenchmarkTest00050");
47
+
48
+ // Code based on example from:
49
+ // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/
50
+ // 8-byte initialization vector
51
+ // byte[] iv = {
52
+ // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2,
53
+ // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033
54
+ // };
55
+ java.security.SecureRandom random = new java.security.SecureRandom();
56
+ byte[] iv = random.generateSeed(8); // DES requires 8 byte keys
57
+
58
+ try {
59
+ javax.crypto.Cipher c =
60
+ javax.crypto.Cipher.getInstance("DES/CBC/PKCS5Padding", "SunJCE");
61
+ // Prepare the cipher to encrypt
62
+ javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey();
63
+ java.security.spec.AlgorithmParameterSpec paramSpec =
64
+ new javax.crypto.spec.IvParameterSpec(iv);
65
+ c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec);
66
+
67
+ // encrypt and store the results
68
+ byte[] input = {(byte) '?'};
69
+ Object inputParam = param;
70
+ if (inputParam instanceof String) input = ((String) inputParam).getBytes();
71
+ if (inputParam instanceof java.io.InputStream) {
72
+ byte[] strInput = new byte[1000];
73
+ int i = ((java.io.InputStream) inputParam).read(strInput);
74
+ if (i == -1) {
75
+ response.getWriter()
76
+ .println(
77
+ "This input source requires a POST, not a GET. Incompatible UI for the InputStream source.");
78
+ return;
79
+ }
80
+ input = java.util.Arrays.copyOf(strInput, i);
81
+ }
82
+ byte[] result = c.doFinal(input);
83
+
84
+ java.io.File fileTarget =
85
+ new java.io.File(
86
+ new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR),
87
+ "passwordFile.txt");
88
+ java.io.FileWriter fw =
89
+ new java.io.FileWriter(fileTarget, true); // the true will append the new data
90
+ fw.write(
91
+ "secret_value="
92
+ + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true)
93
+ + "\n");
94
+ fw.close();
95
+ response.getWriter()
96
+ .println(
97
+ "Sensitive value: '"
98
+ + org.owasp
99
+ .esapi
100
+ .ESAPI
101
+ .encoder()
102
+ .encodeForHTML(new String(input))
103
+ + "' encrypted and stored<br/>");
104
+
105
+ } catch (java.security.NoSuchAlgorithmException e) {
106
+ response.getWriter()
107
+ .println(
108
+ "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case");
109
+ e.printStackTrace(response.getWriter());
110
+ throw new ServletException(e);
111
+ } catch (java.security.NoSuchProviderException e) {
112
+ response.getWriter()
113
+ .println(
114
+ "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case");
115
+ e.printStackTrace(response.getWriter());
116
+ throw new ServletException(e);
117
+ } catch (javax.crypto.NoSuchPaddingException e) {
118
+ response.getWriter()
119
+ .println(
120
+ "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case");
121
+ e.printStackTrace(response.getWriter());
122
+ throw new ServletException(e);
123
+ } catch (javax.crypto.IllegalBlockSizeException e) {
124
+ response.getWriter()
125
+ .println(
126
+ "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case");
127
+ e.printStackTrace(response.getWriter());
128
+ throw new ServletException(e);
129
+ } catch (javax.crypto.BadPaddingException e) {
130
+ response.getWriter()
131
+ .println(
132
+ "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case");
133
+ e.printStackTrace(response.getWriter());
134
+ throw new ServletException(e);
135
+ } catch (java.security.InvalidKeyException e) {
136
+ response.getWriter()
137
+ .println(
138
+ "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case");
139
+ e.printStackTrace(response.getWriter());
140
+ throw new ServletException(e);
141
+ } catch (java.security.InvalidAlgorithmParameterException e) {
142
+ response.getWriter()
143
+ .println(
144
+ "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case");
145
+ e.printStackTrace(response.getWriter());
146
+ throw new ServletException(e);
147
+ }
148
+ response.getWriter()
149
+ .println(
150
+ "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.lang.String) executed");
151
+ }
152
+ }