Log time and targeted host
This commit is contained in:
24
index.mjs
24
index.mjs
@@ -2,13 +2,20 @@ import { createServer } from 'node:http';
|
||||
import { clearInterval, setInterval } from 'node:timers';
|
||||
|
||||
const server = createServer((req, res) => {
|
||||
const connOpenDate = new Date();
|
||||
const attacker = req.headers['x-forwarded-for'];
|
||||
const host = req.headers['x-targeted-host'];
|
||||
|
||||
console.log(
|
||||
`Caught ${req.headers['x-forwarded-for']} on ${req.method} ${req.url}`
|
||||
`[${connOpenDate.toLocaleString()}] ${attacker} targeted ${host} on ${
|
||||
req.method
|
||||
} ${req.url}`
|
||||
);
|
||||
|
||||
let msg = ':) you are an idiot hahahahaha :)';
|
||||
const msg = ':) you are an idiot hahahahaha :)';
|
||||
let charIdx = 0;
|
||||
let intervalId = setInterval(() => {
|
||||
|
||||
const intervalId = setInterval(() => {
|
||||
if (charIdx === msg.length) {
|
||||
charIdx = 0;
|
||||
res.write('\n');
|
||||
@@ -17,7 +24,16 @@ const server = createServer((req, res) => {
|
||||
}
|
||||
}, 3000);
|
||||
|
||||
res.once('close', () => clearInterval(intervalId));
|
||||
res.once('close', () => {
|
||||
const connCloseDate = new Date();
|
||||
const timeDiff = connCloseDate.getTime() - connOpenDate.getTime();
|
||||
const diffText = new Date(timeDiff).toISOString().substring(11, 19);
|
||||
|
||||
clearInterval(intervalId);
|
||||
console.log(
|
||||
`[${connCloseDate.toLocaleString()}] ${attacker} aborted connection after ${diffText}`
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
server.listen(3000);
|
||||
|
||||
Reference in New Issue
Block a user