Repository navigation
Expand file tree
/
Copy pathApiScanner.java
More file actions
executable file
·61 lines (54 loc) · 2.36 KB
/
Copy pathApiScanner.java
File metadata and controls
executable file
·61 lines (54 loc) · 2.36 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
/*
* Decompiled with CFR 0.153-SNAPSHOT (d6f6758-dirty).
*/
package burp.application;
import burp.BurpExtender;
import burp.IHttpRequestResponse;
import burp.application.apitypes.ApiType;
import burp.application.apitypes.actuator.ApiTypeActuator;
import burp.application.apitypes.graphql.ApiTypeGraphQL;
import burp.application.apitypes.rest.ApiTypeRest;
import burp.application.apitypes.soap.ApiTypeSoap;
import burp.application.apitypes.swagger.ApiTypeSwagger;
import burp.utils.CommonUtils;
import java.util.ArrayList;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.function.BiFunction;
public class ApiScanner {
private final ArrayList<BiFunction<IHttpRequestResponse, Boolean, ApiType>> apiTypeConstructors = new ArrayList();
public ApiScanner() {
this.apiTypeConstructors.add(ApiTypeActuator::newInstance);
this.apiTypeConstructors.add(ApiTypeSwagger::newInstance);
this.apiTypeConstructors.add(ApiTypeGraphQL::newInstance);
this.apiTypeConstructors.add(ApiTypeSoap::newInstance);
this.apiTypeConstructors.add(ApiTypeRest::newInstance);
}
public ArrayList<ApiType> detect(final IHttpRequestResponse baseRequestResponse, final boolean isPassive) {
ExecutorService executor = Executors.newFixedThreadPool(this.apiTypeConstructors.size());
final ArrayList<ApiType> apiTypes = new ArrayList<ApiType>();
for (final BiFunction<IHttpRequestResponse, Boolean, ApiType> apiTypeConstructor : this.apiTypeConstructors) {
executor.submit(new Runnable() {
@Override
public void run() {
try {
ApiType apiType = (ApiType) apiTypeConstructor.apply(baseRequestResponse, isPassive);
if (apiType.isFingerprintMatch().booleanValue()) {
apiTypes.add(apiType);
}
} catch (Exception e) {
BurpExtender.getStderr().println(CommonUtils.exceptionToString(e));
}
}
});
}
executor.shutdown();
try {
executor.awaitTermination(5L, TimeUnit.MINUTES);
} catch (Exception exception) {
// empty catch block
}
return apiTypes;
}
}