>>102965955
The address gets changed inside
function forwardDNSQuery(query: Buffer, RESOLVER_PORT: number, resolverIp: string): Promise<Buffer> {
return new Promise((resolve, reject) => {
const client = dgram.createSocket('udp4');
const timeout = setTimeout(() => {
client.close();
reject(new Error('DNS query timed out'));
}, 2000);
client.on('error', (err) => {
clearTimeout(timeout);
client.close();
reject(err);
});
client.on('message', (msg) => {
clearTimeout(timeout);
client.close();
resolve(msg);
});
client.send(query, RESOLVER_PORT, resolverIp, (err) => {
if (err) {
clearTimeout(timeout);
client.close();
reject(err);
}
});
});
}
This function is invoked here
export async function handleDNSQuery(
query: DNSMessage,
RESOLVER_PORT: number,
resolverIp: string
): Promise<DNSMessage> {
const queryBuffer = query.toBuffer();
const forwardedResponse = await forwardDNSQuery(queryBuffer, RESOLVER_PORT, resolverIp);
const response = new DNSMessage(forwardedResponse);
response.packetId = query.packetId;
// Set response flags
response.flags = (response.flags & ~0x7800) |
(query.flags & 0x7800) |
0x8000 |
0x0080;
return response;
}
In the main file I do
const response = await handleDNSQuery(query, RESOLVER_PORT, resolverIp);
Before I do that, the client address is 127.0.0.1.
Right after, it gets changed to the resolver address.
So, what I think is happening, is the remoteInfo from the initial socket gets rewritten to the remoteInfo of the socket I open to communicate with 8.8.8.8:53.
Or the second time I open socket it just stays, disregards the initial socket and sends everything back to the one opened in forwardQuery?
I'm actually losing my shit here I swear:(