2024-07-24 16:40:40 +02:00
|
|
|
import { createServer } from 'node:http';
|
2024-07-26 16:08:05 +02:00
|
|
|
import { setTimeout } from 'node:timers';
|
2024-07-24 16:40:40 +02:00
|
|
|
|
2024-07-25 23:04:36 +02:00
|
|
|
const msg = ':) you are an idiot hahahahaha :)';
|
2024-07-26 16:08:05 +02:00
|
|
|
const minDelay = 1000;
|
|
|
|
|
const maxDelay = 5000;
|
|
|
|
|
const delayDiff = maxDelay - minDelay;
|
|
|
|
|
const randomDelay = () => Math.floor(Math.random() * delayDiff + minDelay);
|
2024-07-25 23:04:36 +02:00
|
|
|
|
2024-07-24 16:40:40 +02:00
|
|
|
const server = createServer((req, res) => {
|
2024-07-24 19:15:07 +02:00
|
|
|
const connOpenDate = new Date();
|
2024-07-26 16:08:05 +02:00
|
|
|
const dateText = connOpenDate.toLocaleString('pl');
|
2024-07-24 19:15:07 +02:00
|
|
|
const attacker = req.headers['x-forwarded-for'];
|
2024-07-24 19:21:05 +02:00
|
|
|
const host = req.headers['x-forwarded-host'];
|
2024-07-26 16:08:05 +02:00
|
|
|
const endpoint = `${req.method} ${req.url}`;
|
|
|
|
|
let charIdx = 0;
|
2024-07-24 19:19:39 +02:00
|
|
|
|
2024-07-26 16:08:05 +02:00
|
|
|
console.log(`[${dateText}] ${attacker} targeted ${host} on ${endpoint}`);
|
2024-07-24 16:40:40 +02:00
|
|
|
|
2024-07-26 16:08:05 +02:00
|
|
|
const hang = () => {
|
|
|
|
|
if (res.closed) return;
|
2024-07-24 19:15:07 +02:00
|
|
|
|
2024-07-24 16:40:40 +02:00
|
|
|
if (charIdx === msg.length) {
|
|
|
|
|
charIdx = 0;
|
|
|
|
|
res.write('\n');
|
|
|
|
|
} else {
|
|
|
|
|
res.write(msg[charIdx++]);
|
|
|
|
|
}
|
2024-07-26 16:08:05 +02:00
|
|
|
|
|
|
|
|
setTimeout(hang, randomDelay());
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
hang();
|
2024-07-24 16:40:40 +02:00
|
|
|
|
2024-07-24 19:15:07 +02:00
|
|
|
res.once('close', () => {
|
|
|
|
|
const connCloseDate = new Date();
|
|
|
|
|
const timeDiff = connCloseDate.getTime() - connOpenDate.getTime();
|
2024-07-26 16:08:05 +02:00
|
|
|
const dateText = connCloseDate.toLocaleString('pl');
|
2024-07-24 19:15:07 +02:00
|
|
|
const diffText = new Date(timeDiff).toISOString().substring(11, 19);
|
|
|
|
|
|
|
|
|
|
console.log(
|
2024-07-26 16:08:05 +02:00
|
|
|
`[${dateText}] ${attacker} aborted connection after ${diffText}`
|
2024-07-24 19:15:07 +02:00
|
|
|
);
|
|
|
|
|
});
|
2024-07-24 16:40:40 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
server.listen(3000);
|