-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
107 lines (85 loc) · 3.28 KB
/
index.js
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
"use strict";
// Dependencies
const dnsResolver = require("dns-resolver")
const puppeteer = require("puppeteer")
const chalk = require("chalk")
const delay = require("delay")
const fs = require("fs")
// Variables
const args = process.argv.slice(2)
var subenujs = {
results: "",
subdomains: null
}
// Functions
async function getSubdomains(){
console.log(`[${chalk.blueBright("INFO")}] Scanning ${args[0]} subdomains.`)
const browser = await puppeteer.launch({ headless: true, args: ["--no-sandbox", "--disable-setuid-sandbox"] })
const page = await browser.newPage()
await page.goto("https://subdomainfinder.c99.nl/", { waitUntil: "domcontentloaded" })
await page.type("#domain", args[0])
await page.click("#privatequery")
await page.click("#scan_subdomains")
await page.waitForSelector("body > div > div.col-md-12 > div:nth-of-type(1) > center > div.row > div > a", { timeout: 0 })
const subdomains = await page.$$eval("#result_table > tbody > tr > td:nth-of-type(2) > a", elems =>{
return elems.map(elem => elem.textContent)
})
subenujs.subdomains = subdomains
console.log(`[${chalk.blueBright("INFO")}] Subdomains scanning finished..`)
await browser.close()
enumerate()
}
function enumerate(){
console.log(`[${chalk.blueBright("INFO")}] Scanning ${args[0]} subdomains DNS.`)
var subdomainIndex = 0
async function enumerateSubdomains(){
await delay(100)
if(subdomainIndex > subenujs.subdomains.length){
console.log(`[${chalk.blueBright("INFO")}] Scanning ${args[0]} subdomains DNS finished.`)
return end()
}
if(!subenujs.subdomains[subdomainIndex].length){
subdomainIndex += 1
return enumerateSubdomains()
}
try{
dnsResolver.configure(subenujs.subdomains[subdomainIndex], function(err, data){
if(err){
subdomainIndex += 1
return enumerateSubdomains()
}
dnsResolver.resolve(subenujs.subdomains[subdomainIndex], function(err, data){
if(err){
subdomainIndex += 1
return enumerateSubdomains()
}
if(subenujs.results.length === 0){
subenujs.results = `${subenujs.subdomains[subdomainIndex]} - ${data}`
}else{
subenujs.results += `\n${subenujs.subdomains[subdomainIndex]} - ${data}`
}
subdomainIndex += 1
enumerateSubdomains()
})
})
}catch{
subdomainIndex += 1
enumerateSubdomains()
}
}
function end(){
fs.writeFile(args[1], subenujs.results, "utf8", function(err){
if(err){
console.log(`[${chalk.redBright("[ERROR]")}] ${err.toString()}`)
console.log(`[${chalk.yellowBright("[WARNING]")}] Aborting...`)
process.exit()
}
console.log(`[${chalk.blueBright("INFO")}] Done.`)
process.exit()
})
}
enumerateSubdomains()
}
// Main
if(!args.length) return console.log("usage: node index.js <domain> <outputFile>")
getSubdomains()