forked from canada-ca/tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
48 lines (41 loc) · 1.02 KB
/
index.js
File metadata and controls
48 lines (41 loc) · 1.02 KB
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
const dns = require('dns2')
const { Packet } = dns
const { DOMAIN, TOKEN } = process.env
const domain = DOMAIN || 'log4shell.tracker.alpha.canada.ca'
const token = TOKEN || 't'
const server = dns.createServer({
udp: true,
tcp: true,
})
server.on('request', (request, send) => {
const response = Packet.createResponseFromRequest(request)
if (request.questions.length === 0) {
send(response)
return
}
const [question] = request.questions
const { name } = question
// Test domain lookup
if (name.endsWith(`.${token}.${domain}`)) {
console.log(
JSON.stringify({
timestamp: Date.now(),
domainHash: name.replace(`.${token}.${domain}`, ''),
}),
)
}
send(response)
})
;(async () => {
const closed = new Promise((resolve) => process.on('SIGINT', resolve))
await server.listen({
udp: 5353,
tcp: 5454,
})
console.log('Listening.')
console.log(server.addresses())
await closed
process.stdout.write('\n')
await server.close()
console.log('Closed.')
})()