Send the message only once to let fail2ban do its thing
This commit is contained in:
22
index.mjs
22
index.mjs
@@ -10,22 +10,17 @@ const randomDelay = () => Math.floor(Math.random() * delayDiff + minDelay);
|
|||||||
const server = createServer((req, res) => {
|
const server = createServer((req, res) => {
|
||||||
const connOpenDate = new Date();
|
const connOpenDate = new Date();
|
||||||
const dateText = connOpenDate.toLocaleString('pl');
|
const dateText = connOpenDate.toLocaleString('pl');
|
||||||
const attacker = req.headers['x-forwarded-for'];
|
const scannerIP = req.headers['x-forwarded-for'];
|
||||||
const host = req.headers['x-forwarded-host'];
|
const host = req.headers['x-forwarded-host'];
|
||||||
const endpoint = `${req.method} ${req.url}`;
|
const endpoint = `${req.method} ${req.url}`;
|
||||||
let charIdx = 0;
|
let charIdx = 0;
|
||||||
|
|
||||||
console.log(`[${dateText}] ${attacker} targeted ${host} on ${endpoint}`);
|
console.log(`[${dateText}] ${scannerIP} targeted ${host} on ${endpoint}`);
|
||||||
|
|
||||||
const hang = () => {
|
const hang = () => {
|
||||||
if (res.closed) return;
|
if (res.closed) return;
|
||||||
|
else if (charIdx === msg.length) res.end('\n');
|
||||||
if (charIdx === msg.length) {
|
else res.write(msg[charIdx++]);
|
||||||
charIdx = 0;
|
|
||||||
res.write('\n');
|
|
||||||
} else {
|
|
||||||
res.write(msg[charIdx++]);
|
|
||||||
}
|
|
||||||
|
|
||||||
setTimeout(hang, randomDelay());
|
setTimeout(hang, randomDelay());
|
||||||
};
|
};
|
||||||
@@ -36,11 +31,12 @@ const server = createServer((req, res) => {
|
|||||||
const connCloseDate = new Date();
|
const connCloseDate = new Date();
|
||||||
const timeDiff = connCloseDate.getTime() - connOpenDate.getTime();
|
const timeDiff = connCloseDate.getTime() - connOpenDate.getTime();
|
||||||
const dateText = connCloseDate.toLocaleString('pl');
|
const dateText = connCloseDate.toLocaleString('pl');
|
||||||
const diffText = new Date(timeDiff).toISOString().substring(11, 19);
|
const diffText = new Date(timeDiff).toISOString().substring(14, 19);
|
||||||
|
|
||||||
console.log(
|
const hangResult =
|
||||||
`[${dateText}] ${attacker} aborted connection after ${diffText}`
|
charIdx === msg.length ? 'received the message' : 'aborted connection';
|
||||||
);
|
|
||||||
|
console.log(`[${dateText}] ${scannerIP} ${hangResult} after ${diffText}`);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user