-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMain.java
More file actions
128 lines (124 loc) · 6.04 KB
/
Main.java
File metadata and controls
128 lines (124 loc) · 6.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package com.contrastsecurity.webgoat.selenium;
public class Main {
static String un = "testun"; // Username
static String pw = "testpw"; // Password
static String host = "localhost"; // Hostname
static String contextRoot = "/WebGoat"; // Context root
static private String port ="null"; // Port
static private boolean ssl = false; // HTTPS (true) or HTTP (false - default)
static private boolean headless = false;
static private boolean chrome = false;
static private boolean firefox = false;
static private String driverPath = "null";
static private String browserBin = "null";
static private boolean proxy = false;
static String proxyHost = "127.0.0.1"; // Default proxy host
static String proxyPort = "8080"; // Default proxy port
public static void main(String[] args) {
String port_regex = "([0-9]|[1-8][0-9]|9[0-9]|[1-8][0-9]{2}|9[0-8][0-9]|99[0-9]|[1-8][0-9]{3}|9[0-8][0-9]{2}|99[0-8][0-9]|999[0-9]|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])";
for (int i = 0; i < args.length; i++) {
if (args[i].equals("-help")) {
Utility.help();
return;
}
}
for (int i = 0; i < args.length; i++) {
switch (args[i]) {
case "-un":
if (i == args.length - 1 || args[i + 1].charAt(0) == '-')
throw new IllegalArgumentException("Expected argument after: " + args[i]);
un = args[i++ + 1];
break;
case "-pw":
if (i == args.length - 1 || args[i + 1].charAt(0) == '-')
throw new IllegalArgumentException("Expected argument after: " + args[i]);
pw = args[i++ + 1];
break;
case "-host":
if (i == args.length -1 || args[i + 1].charAt(0) == '-')
throw new IllegalArgumentException("Expected argument after: " + args[i]);
host = args[i++ + 1];
break;
case "-port":
if (i == args.length -1 || args[i + 1].charAt(0) == '-')
throw new IllegalArgumentException("Expected argument after: " + args[i]);
if (!args[i + 1].matches(port_regex))
throw new IllegalArgumentException("Not a valid port: " + args[i + 1] + ". Valid ports are 0-65535.");
port = args[i++ + 1];
break;
case "-ssl":
ssl = true;
break;
case "-headless":
headless = true;
break;
case "-proxy":
proxy = true;
break;
case "-proxyHost":
if (i == args.length -1 || args[i + 1].charAt(0) == '-')
throw new IllegalArgumentException("Expected argument after: " + args[i]);
proxyHost = args[i++ + 1];
break;
case "-proxyPort":
if (i == args.length -1 || args[i + 1].charAt(0) == '-')
throw new IllegalArgumentException("Expected argument after: " + args[i]);
if (!args[i + 1].matches(port_regex))
throw new IllegalArgumentException("Not a valid proxyPort: " + args[i + 1] + ". Valid ports are 0-65535.");
proxyPort = args[i++ + 1];
break;
case "-driver":
if (i == args.length -1 || args[i + 1].charAt(0) == '-')
throw new IllegalArgumentException("Expected argument after: " + args[i]);
driverPath = args[i++ + 1];
break;
case "-bin":
if (i == args.length -1 || args[i + 1].charAt(0) == '-')
throw new IllegalArgumentException("Expected argument after: " + args[i]);
browserBin = args[i++ + 1];
break;
case "-cr":
if (i == args.length -1 || args[i + 1].charAt(0) == '-')
throw new IllegalArgumentException("Expected argument after: " + args[i]);
contextRoot = args[i++ + 1];
break;
case "-chrome":
if (firefox) {
throw new IllegalArgumentException("Cannot specify both -chrome and -firefox switches. Please specify only one.");
}
chrome = true;
break;
case "-firefox":
if (chrome) {
throw new IllegalArgumentException("Cannot specify both -chrome and -firefox switches. Please specify only one.");
}
firefox = true;
break;
default:
throw new IllegalArgumentException("Not a valid option: " + args[i]);
}
}
if (!chrome && !firefox) {
firefox = true; // Set Firefox as default browser if browser not specified
}
if (driverPath.equals("null")) {
driverPath = Utility.defaultDriverPath(firefox);
}
String baseUrl = Utility.getUrl(host, port, contextRoot, ssl);
System.out.println("un: " + un);
System.out.println("pw: " + pw);
System.out.println("host: " + host);
System.out.println("port: " + port);
if (proxy){
System.out.println("proxyHost: " + proxyHost);
System.out.println("proxyPort: " + proxyPort);
}
System.out.println("ssl: " + ssl);
System.out.println("url: " + baseUrl);
if (firefox) {
FirefoxScript.run(un, pw, baseUrl, headless, proxy, proxyHost, proxyPort, driverPath, browserBin);
} else {
ChromeScript.run(un, pw, baseUrl, headless, proxy, proxyHost, proxyPort, driverPath, browserBin);
}
}
}