-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dnsClass.js
136 lines (116 loc) · 6.16 KB
/
dnsClass.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
const fetch = require('node-fetch');
const cheerio = require('cheerio');
const version = require('./package.json').version;
class DnsPrivate {
constructor() {
this.mainUrl = 'https://dnsdumpster.com/';
}
info = () => new Promise(async (resolve, reject) => {
resolve({
name: "DNSDumpster NodeJS non-official SDK",
description: "DNS Dumpster is a free domain research tool that can discover hosts related to a domain. Finding visible hosts from the attackers perspective is an important part of the security assessment process.",
version: version
})
});
get = (ip_or_domain) => new Promise(async (resolve, reject) => {
await fetch(this.mainUrl)
.then(res => res.text())
.then(async body_ => {
const $ = cheerio.load(body_);
const csrf = $('input[name="csrfmiddlewaretoken"]').val();
const response = await fetch(this.mainUrl, {
method: 'post',
headers: {
referer: this.mainUrl,
cookie: "csrftoken=" + csrf,
"content-type": "application/x-www-form-urlencoded"
},
body: new URLSearchParams({
csrfmiddlewaretoken: csrf,
targetip: ip_or_domain,
user: 'free',
}).toString()
}).catch(err => reject(err));
const body = await response.text();
const $2 = cheerio.load(body);
if ($2('body').text().includes('Too many requests from your IP address')) return reject("Too many requests from your IP address");
if (!$2('.col-md-12').length) return reject("Failed to parse data");
var results = [];
const tables = $2('.col-md-12').find('table');
tables.each((i, table) => {
var p = $2(table).parent().prev('p').text();
if (p.includes('MX')) p = "MX Records";
else if (p.includes('Host Records')) p = "Host Records"
else if (p.includes('TXT Records')) p = "TXT Records"
const rows = $2(table).find('tr');
var currentT = {
detail: p,
data: []
}
rows.each((j, row) => {
const columns = $2(row).find('td');
var col = [];
columns.each((k, column) => {
var text = $2(column).contents().filter(function () {
return this.nodeType == 3;
}).text();
var save = text.replace(/(\r\n|\n|\r)/gm, "");
if (currentT.detail.includes("Host Records") || currentT.detail.includes("MX Records") || currentT.detail.includes("DNS Servers")) {
col.push({
id: k,
data: save
})
} else {
col.push(save);
}
});
if (currentT.detail.includes("Host Records") || currentT.detail.includes("MX Records") || currentT.detail.includes("DNS Servers")) {
for (var i = 0; i < col.length; i++) {
if (i == 0) {
if (currentT.detail.includes("MX Records")) {
var split = col[i].data.split(" ");
var priority = split[0];
var domain = split[1];
if (domain[domain.length - 1] == ".") domain = domain.slice(0, -1);
currentT.data.push({
priority: priority,
domain: domain
});
} else if (currentT.detail.includes("DNS Servers")) {
var domain = col[i].data;
if (domain[domain.length - 1] == ".") domain = domain.slice(0, -1);
currentT.data.push({
domain: domain
});
} else {
var domain = col[i].data;
if (domain[domain.length - 1] == ".") domain = domain.slice(0, -1);
else if (domain[domain.length - 1] == " ") domain = domain.slice(0, -1);
currentT.data.push({
domain: domain
});
}
} else if (i == 1) {
currentT.data[currentT.data.length - 1].ip = col[i].data;
} else if (i == 2) {
currentT.data[currentT.data.length - 1].provider = col[i].data;
}
}
} else if (currentT.detail.includes("TXT Records")) {
currentT.data.push(...col);
} else {
currentT.data.push(col);
}
});
results.push(currentT);
});
resolve({
success: true,
data: results
});
}).catch(err => {
reject(err);
})
});
}
module.exports = DnsPrivate;