-
Notifications
You must be signed in to change notification settings - Fork 9
/
build.gradle
239 lines (203 loc) · 8 KB
/
build.gradle
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
// Apply the Java plugin
apply plugin: 'java'
// Use Maven (because Burp Extender is on Maven)
repositories {
mavenCentral()
}
dependencies {
// Add the Burp Extender interface
// https://mvnrepository.com/artifact/net.portswigger.burp.extender/burp-extender-api
compile group: 'net.portswigger.burp.extender', name: 'burp-extender-api', version: '2.1'
// https://mvnrepository.com/artifact/com.google.code.gson/gson
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.6'
// https://mvnrepository.com/artifact/commons-io/commons-io
compile group: 'commons-io', name: 'commons-io', version: '2.6'
// https://mvnrepository.com/artifact/org.apache.commons/commons-exec
compile group: 'org.apache.commons', name: 'commons-exec', version: '1.3'
// https://mvnrepository.com/artifact/org.xerial/sqlite-jdbc
// Adds almost 6 MBs to the final jar file :(
compile group: 'org.xerial', name: 'sqlite-jdbc', version: '3.30.1'
}
sourceSets {
main {
java {
// Set the source directory to "src"
srcDir 'src'
// Exclude 'resources'
exclude 'resources/'
}
}
main {
resources {
// Set the resource directory to "src/resources"
srcDir 'src/resources'
}
}
}
// Put the final jar file in a different location
libsDirName = '../release'
// Create a task for bundling all dependencies into a jar file.
task bigJar(type: Jar) {
baseName = project.name + '-all'
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
with jar
}
// Extend clean to delete eslint-security
clean.doFirst {
println 'Deleting eslint-security'
delete 'eslint-security'
println 'Deleting release'
delete 'release'
}
// Create the install task here.
// OS Detection. Source: https://stackoverflow.com/a/54315477
import org.apache.tools.ant.taskdefs.condition.Os
// How to use example.
// task executeCommand(type: Exec) {
// commandLine osAdaptiveCommand('aws', 'ecr', 'get-login', '--no-include-email')
// }
private static Iterable<String> osAdaptiveCommand(String... commands) {
def newCommands = []
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
newCommands = ['cmd', '/c']
}
newCommands.addAll(commands)
return newCommands
}
// End of OS detection.
// The install task will:
// 1. Build the extension jar.
// 2. Get the git submodule in `eslint-security`.
// 3. Runs `npm-install` in `eslint-security`.
task install() {
// 2. Build the project via gradle.
dependsOn 'bigJar'
// If these are not in doLast, they will be executed in the configuration
// phase. AKA every time any task is run.
doLast {
println '\ngit submodule update --init --recursive --remote'
exec {
// 2. Get the eslint-security git submodule.
commandLine osAdaptiveCommand('git', 'submodule', 'update', '--init', '--recursive', '--remote')
}
println '\ncd eslint-security & npm install'
exec {
// 3. Navigate to eslint-security and run npm install.
commandLine osAdaptiveCommand('cd', 'eslint-security', '&&', 'npm', 'install')
}
}
}
import java.nio.file.Files
import java.nio.file.Paths
import java.io.File
task config() {
doLast {
// Check if target was provided.
// 1. Read a command-line parameter. This will be the project path.
if (!project.hasProperty('target')) {
// Return an error if target is not provided.
println 'Please provide the target path in this format'
println 'Relative path: `gradlew config -Ptarget=/relative/path/to/target'
println 'Absolute path: `gradlew config -Ptarget=c:/absolute/path/to/target'
throw new GradleException('target parameter not provided')
}
String currentDir = System.properties['user.dir']
// 2. Check if install has been called by checking for the existence of
// currentDir/eslint-security/node_modules. If it's not there, return
// an error.
if (Files.isDirectory(Paths.get(currentDir, 'eslint-security/node_modules'))) {
println 'eslint-security/node_modules exists'
} else {
throw new GradleException('`eslint-security/node_modules` does not exist, have you run `gradlew install')
}
// 3. Check if target is an absolute path.
String targetDir = project.target
File tar = new File(targetDir)
if (!tar.isAbsolute()) {
// If target is not absolute, concat target with the current working
// directory and normalize it.
targetDir = Paths.get(currentDir, targetDir).normalize()
}
// 4.1 Path to store extracted JavaScript files: `target/beautified`
String beautified = Paths.get(targetDir, "beautified").toString().replace("\\", "/")
// 4.2 Path to store ESLint results: `target/linted`
String linted = Paths.get(targetDir, "linted").toString().replace("\\", "/")
// 4.3 Location of the target database: `target/eslinter.sqlite`
String db = Paths.get(targetDir, "eslinter.sqlite").toString().replace("\\", "/")
// 4.4 Path to the eslint command: `currentDir/eslint-security/node_modules/.bin/eslint`
String eslint = Paths.get(currentDir, 'eslint-security/node_modules/.bin/eslint').toString().replace("\\", "/")
// 4.5 Path to the js-beautify command: `currentDir/eslint-security/node_modules/.bin/js-beautify`
String jsbeautify = Paths.get(currentDir, 'eslint-security/node_modules/.bin/js-beautify').toString().replace("\\", "/")
// 4.6 Detect OS. If Windows, add ".cmd" to the end of commands.
if (System.properties['os.name'].toLowerCase().contains('windows')) {
eslint += ".cmd"
jsbeautify += ".cmd"
}
// 4.7 Path to the ESLint configuration file: `currentDir/eslint-security/configs/eslintrc-light.js`
String cfgFile = Paths.get(currentDir, 'eslint-security/configs/eslintrc-parsia.js').toString().replace("\\", "/")
// 5.0 Create the json file.
String cfgStr =
"""
{
"beautified-javascript-path": "${beautified}",
"lint-result-path": "${linted}",
"database-path": "${db}",
"eslint-config-path": "${cfgFile}",
"eslint-command-path": "${eslint}",
"jsbeautify-command-path": "${jsbeautify}",
"only-process-in-scope": false,
"highlight": true,
"diagnostics": false,
"process-tool-list": [
"Proxy",
"Scanner",
"Repeater"
],
"number-of-linting-threads": 3,
"lint-timeout": 60,
"number-of-request-threads": 10,
"threadpool-timeout": 10,
"lint-task-delay": 10,
"update-table-delay": 5,
"maximum-js-size": 0,
"js-mime-types": [
"application/javascript",
"application/ecmascript",
"application/x-ecmascript",
"application/x-javascript",
"text/javascript",
"text/ecmascript",
"text/javascript1.0",
"text/javascript1.1",
"text/javascript1.2",
"text/javascript1.3",
"text/javascript1.4",
"text/javascript1.5",
"text/jscript",
"text/livescript",
"text/x-ecmascript",
"text/x-javascript",
"script"
],
"javascript-file-extensions": [
"js",
"javascript"
],
"contains-javascript": [
"text/html",
"application/xhtml+xml"
],
"removable-headers": [
"If-Modified-Since",
"If-None-Match"
]
}
"""
File configFile = new File(Paths.get(currentDir, 'release/config.json').toString())
configFile.write(cfgStr)
println "Configuration finished."
println "Results will be stored in ${targetDir.toString().toString().replace("\\", "/")}."
println "Config file is stored at ${Paths.get(currentDir,'release/config.json').toString().replace("\\", "/")}."
println "Add the extension jar file to Burp and start linting."
}
}