|
| 1 | +/** |
| 2 | + * This script uses the API of ARPSyndicate's Subdomain Center (https://www.subdomain.center/) to |
| 3 | + * find and add subdomains to the Sites Tree. When it is enabled, it runs automatically for each |
| 4 | + * new domain added to the Sites Tree. |
| 5 | + */ |
| 6 | + |
| 7 | +const HistoryReference = Java.type("org.parosproxy.paros.model.HistoryReference") |
| 8 | +const HttpSender = Java.type("org.parosproxy.paros.network.HttpSender") |
| 9 | +const HttpMessage = Java.type("org.parosproxy.paros.network.HttpMessage") |
| 10 | +const URI = Java.type("org.apache.commons.httpclient.URI") |
| 11 | +const requestedSubdomains = [] |
| 12 | +const sender = new HttpSender(HttpSender.MANUAL_REQUEST_INITIATOR) |
| 13 | + |
| 14 | +function consumer(event) { |
| 15 | + if (event.getEventType() != "site.added") return |
| 16 | + try { |
| 17 | + const siteNode = event.getTarget().getStartNode() |
| 18 | + const host = siteNode.getHistoryReference().getURI().getHost() |
| 19 | + if (requestedSubdomains.indexOf(host) != -1) { |
| 20 | + // Don't run for subdomain nodes created by this script |
| 21 | + return |
| 22 | + } |
| 23 | + const apiUri = new URI(`https://api.subdomain.center/?domain=${host}`, true) |
| 24 | + const apiMsg = new HttpMessage(apiUri) |
| 25 | + sender.sendAndReceive(apiMsg) |
| 26 | + const subdomains = JSON.parse(apiMsg.getResponseBody().toString()) |
| 27 | + subdomains.forEach(function (subdomain) { |
| 28 | + const uri = new URI(`https://${subdomain}`, true) |
| 29 | + const msg = new HttpMessage(uri) |
| 30 | + const extHistory = control.getExtensionLoader().getExtension("ExtensionHistory") |
| 31 | + try { |
| 32 | + sender.sendAndReceive(msg) |
| 33 | + const href = new HistoryReference(model.getSession(), HistoryReference.TYPE_ZAP_USER, msg) |
| 34 | + extHistory.addHistory(href) |
| 35 | + requestedSubdomains.push(subdomain) |
| 36 | + } catch (err) { |
| 37 | + print(`Failed to send a request to "https://${subdomain}": ${err.getMessage()}.`) |
| 38 | + } |
| 39 | + }) |
| 40 | + } catch (err) { |
| 41 | + print(`There was an error while trying to get subdomains using Subdomain Center: ${err}`) |
| 42 | + } |
| 43 | +} |
| 44 | + |
| 45 | +function install(helper) { |
| 46 | + org.zaproxy.zap.ZAP.getEventBus().registerConsumer(consumer, "org.parosproxy.paros.model.SiteMapEventPublisher") |
| 47 | +} |
| 48 | + |
| 49 | +function uninstall(helper) { |
| 50 | + org.zaproxy.zap.ZAP.getEventBus().unregisterConsumer(consumer) |
| 51 | +} |
0 commit comments