-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
61 lines (51 loc) · 1.76 KB
/
app.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
const express = require('express');
const path = require('path');
const dns = require('dns');
const axios = require('axios');
const app = express();
// Serve static files (HTML, CSS, JS)
app.use(express.static(path.join(__dirname, 'public')));
// Parse JSON data from incoming requests
app.use(express.json());
// DNS Query to discover subdomains
const getSubdomainsFromDNS = async (domain) => {
return new Promise((resolve, reject) => {
dns.resolve(domain, 'A', (err, records) => {
if (err) reject(err);
resolve(records);
});
});
};
// Query a third-party API to discover subdomains (e.g., for public sources)
const getSubdomainsFromAPI = async (domain) => {
try {
const response = await axios.get(`https://api.hackertarget.com/hostsearch/?q=${domain}`);
return response.data.split('\n').map(line => line.split(',')[0]);
} catch (error) {
return [];
}
};
// Main API route to discover subdomains
app.post('/enumerate', async (req, res) => {
const domain = req.body.domain;
let results = [];
try {
// Step 1: DNS enumeration
const dnsSubdomains = await getSubdomainsFromDNS(domain);
results = [...results, ...dnsSubdomains];
// Step 2: Third-party API enumeration
const apiSubdomains = await getSubdomainsFromAPI(domain);
results = [...results, ...apiSubdomains];
res.json({ results });
} catch (error) {
res.status(500).json({ error: 'Error enumerating subdomains' });
}
});
// Serve index.html for the root route
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'public', 'index.html'));
});
const port = 8080;
app.listen(port, () => {
console.log(`Server running at http://localhost:${port}`);
});