Skip to content

Commit da26fe5

Browse files
authored
Merge pull request #395 from ricekot/script/subdomain-center-api
2 parents 7e56388 + 6de007b commit da26fe5

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ All notable changes to this add-on will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
55

66
## [Unreleased]
7-
7+
### Added
8+
- extender/arpSyndicateSubdomainDiscovery.js - uses the API of [ARPSyndicate's Subdomain Center](https://www.subdomain.center/)
9+
to find and add subdomains to the Sites Tree.
810

911
## [18] - 2024-01-29
1012
### Added
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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

Comments
 (0)