forked from zaproxy/community-scripts
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy patharpSyndicateSubdomainDiscovery.js
More file actions
70 lines (66 loc) · 2.25 KB
/
Copy patharpSyndicateSubdomainDiscovery.js
File metadata and controls
70 lines (66 loc) · 2.25 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
/**
* This script uses the API of ARPSyndicate's Subdomain Center (https://www.subdomain.center/) to
* find and add subdomains to the Sites Tree. When it is enabled, it runs automatically for each
* new domain added to the Sites Tree.
*/
const HistoryReference = Java.type(
"org.parosproxy.paros.model.HistoryReference"
);
const HttpSender = Java.type("org.parosproxy.paros.network.HttpSender");
const HttpMessage = Java.type("org.parosproxy.paros.network.HttpMessage");
const URI = Java.type("org.apache.commons.httpclient.URI");
const ZAP = Java.type("org.zaproxy.zap.ZAP");
const requestedSubdomains = [];
const sender = new HttpSender(HttpSender.MANUAL_REQUEST_INITIATOR);
function consumer(event) {
if (event.getEventType() != "site.added") return;
try {
const siteNode = event.getTarget().getStartNode();
const host = siteNode.getHistoryReference().getURI().getHost();
if (requestedSubdomains.indexOf(host) != -1) {
// Don't run for subdomain nodes created by this script
return;
}
const apiUri = new URI(
`https://api.subdomain.center/?domain=${host}`,
true
);
const apiMsg = new HttpMessage(apiUri);
sender.sendAndReceive(apiMsg);
const subdomains = JSON.parse(apiMsg.getResponseBody().toString());
subdomains.forEach(function (subdomain) {
const uri = new URI(`https://${subdomain}`, true);
const msg = new HttpMessage(uri);
const extHistory = control
.getExtensionLoader()
.getExtension("ExtensionHistory");
try {
sender.sendAndReceive(msg);
const href = new HistoryReference(
model.getSession(),
HistoryReference.TYPE_ZAP_USER,
msg
);
extHistory.addHistory(href);
requestedSubdomains.push(subdomain);
} catch (err) {
print(
`Failed to send a request to "https://${subdomain}": ${err.getMessage()}.`
);
}
});
} catch (err) {
print(
`There was an error while trying to get subdomains using Subdomain Center: ${err}`
);
}
}
function install(helper) {
ZAP.getEventBus().registerConsumer(
consumer,
"org.parosproxy.paros.model.SiteMapEventPublisher"
);
}
function uninstall(helper) {
ZAP.getEventBus().unregisterConsumer(consumer);
}