|
1 |
| - |
2 | 1 | package org.owasp.webgoat.session;
|
3 | 2 |
|
| 3 | +import java.io.File; |
4 | 4 | import java.io.FileInputStream;
|
5 | 5 | import java.io.IOException;
|
6 | 6 | import java.util.Properties;
|
7 |
| - |
8 |
| - |
9 |
| -/*************************************************************************************************** |
10 |
| - * |
11 |
| - * |
12 |
| - * This file is part of WebGoat, an Open Web Application Security Project utility. For details, |
13 |
| - * please see http://www.owasp.org/ |
14 |
| - * |
| 7 | +import org.owasp.webgoat.HammerHead; |
| 8 | +import org.slf4j.Logger; |
| 9 | +import org.slf4j.LoggerFactory; |
| 10 | + |
| 11 | +/** |
| 12 | + * ************************************************************************************************* |
| 13 | + * |
| 14 | + * |
| 15 | + * This file is part of WebGoat, an Open Web Application Security Project |
| 16 | + * utility. For details, please see http://www.owasp.org/ |
| 17 | + * |
15 | 18 | * Copyright (c) 2002 - 2007 Bruce Mayhew
|
16 |
| - * |
17 |
| - * This program is free software; you can redistribute it and/or modify it under the terms of the |
18 |
| - * GNU General Public License as published by the Free Software Foundation; either version 2 of the |
19 |
| - * License, or (at your option) any later version. |
20 |
| - * |
21 |
| - * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without |
22 |
| - * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
23 |
| - * General Public License for more details. |
24 |
| - * |
25 |
| - * You should have received a copy of the GNU General Public License along with this program; if |
26 |
| - * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
27 |
| - * 02111-1307, USA. |
28 |
| - * |
| 19 | + * |
| 20 | + * This program is free software; you can redistribute it and/or modify it under |
| 21 | + * the terms of the GNU General Public License as published by the Free Software |
| 22 | + * Foundation; either version 2 of the License, or (at your option) any later |
| 23 | + * version. |
| 24 | + * |
| 25 | + * This program is distributed in the hope that it will be useful, but WITHOUT |
| 26 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 27 | + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
| 28 | + * details. |
| 29 | + * |
| 30 | + * You should have received a copy of the GNU General Public License along with |
| 31 | + * this program; if not, write to the Free Software Foundation, Inc., 59 Temple |
| 32 | + * Place - Suite 330, Boston, MA 02111-1307, USA. |
| 33 | + * |
29 | 34 | * Getting Source ==============
|
30 |
| - * |
31 |
| - * Source for this application is maintained at code.google.com, a repository for free software |
32 |
| - * projects. |
33 |
| - * |
| 35 | + * |
| 36 | + * Source for this application is maintained at code.google.com, a repository |
| 37 | + * for free software projects. |
| 38 | + * |
34 | 39 | * For details, please see http://code.google.com/p/webgoat/
|
35 | 40 | */
|
36 |
| -public class WebgoatProperties extends Properties |
37 |
| -{ |
38 |
| - |
39 |
| - /** |
40 |
| - * |
41 |
| - */ |
42 |
| - private static final long serialVersionUID = 4351681705558227918L; |
43 |
| - |
44 |
| - public WebgoatProperties(String propertiesFileName) throws IOException |
45 |
| - { |
46 |
| - try |
47 |
| - { |
48 |
| - FileInputStream in = new FileInputStream(propertiesFileName); |
49 |
| - load(in); |
50 |
| - } catch (IOException e) |
51 |
| - { |
52 |
| - System.out.println("Warning: Unable to open webgoat.properties file"); |
53 |
| - } |
54 |
| - } |
55 |
| - |
56 |
| - public int getIntProperty(String key, int defaultValue) |
57 |
| - { |
58 |
| - int value = defaultValue; |
59 |
| - |
60 |
| - String s = getProperty(key); |
61 |
| - if (s != null) |
62 |
| - { |
63 |
| - value = Integer.parseInt(s); |
64 |
| - } |
65 |
| - |
66 |
| - return value; |
67 |
| - } |
68 |
| - |
69 |
| - public boolean getBooleanProperty(String key, boolean defaultValue) |
70 |
| - { |
71 |
| - boolean value = defaultValue; |
72 |
| - key = this.trimLesson(key); |
73 |
| - |
74 |
| - String s = getProperty(key); |
75 |
| - if (s != null) |
76 |
| - { |
77 |
| - if (s.equalsIgnoreCase("true")) |
78 |
| - value = true; |
79 |
| - else if (s.equalsIgnoreCase("yes")) |
80 |
| - value = true; |
81 |
| - else if (s.equalsIgnoreCase("on")) |
82 |
| - value = true; |
83 |
| - else if (s.equalsIgnoreCase("false")) |
84 |
| - value = false; |
85 |
| - else if (s.equalsIgnoreCase("no")) |
86 |
| - value = false; |
87 |
| - else if (s.equalsIgnoreCase("off")) value = false; |
88 |
| - } |
89 |
| - |
90 |
| - return value; |
91 |
| - } |
92 |
| - |
93 |
| - private String trimLesson(String lesson) |
94 |
| - { |
95 |
| - String result = ""; |
96 |
| - |
97 |
| - if (lesson.startsWith("org.owasp.webgoat.lessons.")) |
98 |
| - { |
99 |
| - result = lesson.substring("org.owasp.webgoat.lessons.".length(), lesson.length()); |
100 |
| - } |
101 |
| - else |
102 |
| - { |
103 |
| - result = lesson; |
104 |
| - } |
105 |
| - |
106 |
| - return result; |
107 |
| - } |
108 |
| - |
109 |
| - public static void main(String[] args) |
110 |
| - { |
111 |
| - WebgoatProperties properties = null; |
112 |
| - try |
113 |
| - { |
114 |
| - properties = new WebgoatProperties("C:\\webgoat.properties"); |
115 |
| - } catch (IOException e) |
116 |
| - { |
117 |
| - System.out.println("Error loading properties"); |
118 |
| - e.printStackTrace(); |
119 |
| - } |
120 |
| - System.out.println(properties.getProperty("CommandInjection.category")); |
121 |
| - } |
| 41 | +public class WebgoatProperties extends Properties { |
| 42 | + |
| 43 | + /** |
| 44 | + * |
| 45 | + */ |
| 46 | + private static final long serialVersionUID = 4351681705558227918L; |
| 47 | + final Logger logger = LoggerFactory.getLogger(WebgoatProperties.class); |
| 48 | + |
| 49 | + public WebgoatProperties(String propertiesFileName) throws IOException { |
| 50 | + if (propertiesFileName == null) { |
| 51 | + throw new IOException("Path to webgoat.properties is null, initialization must have failed"); |
| 52 | + } |
| 53 | + File propertiesFile = new File(propertiesFileName); |
| 54 | + if (propertiesFile.exists() == false) { |
| 55 | + throw new IOException("Unable to locate webgoat.properties at: " + propertiesFileName); |
| 56 | + } |
| 57 | + FileInputStream in = new FileInputStream(propertiesFile); |
| 58 | + load(in); |
| 59 | + } |
| 60 | + |
| 61 | + public int getIntProperty(String key, int defaultValue) { |
| 62 | + int value = defaultValue; |
| 63 | + |
| 64 | + String s = getProperty(key); |
| 65 | + if (s != null) { |
| 66 | + value = Integer.parseInt(s); |
| 67 | + } |
| 68 | + |
| 69 | + return value; |
| 70 | + } |
| 71 | + |
| 72 | + public boolean getBooleanProperty(String key, boolean defaultValue) { |
| 73 | + boolean value = defaultValue; |
| 74 | + key = this.trimLesson(key); |
| 75 | + |
| 76 | + String s = getProperty(key); |
| 77 | + if (s != null) { |
| 78 | + if (s.equalsIgnoreCase("true")) { |
| 79 | + value = true; |
| 80 | + } else if (s.equalsIgnoreCase("yes")) { |
| 81 | + value = true; |
| 82 | + } else if (s.equalsIgnoreCase("on")) { |
| 83 | + value = true; |
| 84 | + } else if (s.equalsIgnoreCase("false")) { |
| 85 | + value = false; |
| 86 | + } else if (s.equalsIgnoreCase("no")) { |
| 87 | + value = false; |
| 88 | + } else if (s.equalsIgnoreCase("off")) { |
| 89 | + value = false; |
| 90 | + } |
| 91 | + } |
| 92 | + |
| 93 | + return value; |
| 94 | + } |
| 95 | + |
| 96 | + private String trimLesson(String lesson) { |
| 97 | + String result = ""; |
| 98 | + |
| 99 | + if (lesson.startsWith("org.owasp.webgoat.lessons.")) { |
| 100 | + result = lesson.substring("org.owasp.webgoat.lessons.".length(), lesson.length()); |
| 101 | + } else { |
| 102 | + result = lesson; |
| 103 | + } |
| 104 | + |
| 105 | + return result; |
| 106 | + } |
| 107 | + |
| 108 | + public static void main(String[] args) { |
| 109 | + WebgoatProperties properties = null; |
| 110 | + try { |
| 111 | + properties = new WebgoatProperties("C:\\webgoat.properties"); |
| 112 | + } catch (IOException e) { |
| 113 | + System.out.println("Error loading properties"); |
| 114 | + e.printStackTrace(); |
| 115 | + } |
| 116 | + System.out.println(properties.getProperty("CommandInjection.category")); |
| 117 | + } |
122 | 118 |
|
123 | 119 | }
|
0 commit comments