Skip to content

Commit

Permalink
Add subdomain finder extender script
Browse files Browse the repository at this point in the history
Add an extender script that uses the API of ARPSyndicate's Subdomain Center
(https://www.subdomain.center/) to find and add subdomains to the Sites Tree.

Signed-off-by: ricekot <[email protected]>
  • Loading branch information
ricekot committed Feb 9, 2024
1 parent 7e56388 commit 6de007b
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ All notable changes to this add-on will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [Unreleased]

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

## [18] - 2024-01-29
### Added
Expand Down
51 changes: 51 additions & 0 deletions extender/arpSyndicateSubdomainDiscovery.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* 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 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) {
org.zaproxy.zap.ZAP.getEventBus().registerConsumer(consumer, "org.parosproxy.paros.model.SiteMapEventPublisher")
}

function uninstall(helper) {
org.zaproxy.zap.ZAP.getEventBus().unregisterConsumer(consumer)
}

0 comments on commit 6de007b

Please sign in to comment.