Log time and targeted host
This commit is contained in:
@@ -2,6 +2,7 @@ FROM node:lts-alpine
|
|||||||
USER node
|
USER node
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
ENV NODE_ENV production
|
ENV NODE_ENV production
|
||||||
|
ENV TZ Europe/Warsaw
|
||||||
COPY --chown=node:node index.mjs ./
|
COPY --chown=node:node index.mjs ./
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
CMD ["node", "./index.mjs"]
|
CMD ["node", "./index.mjs"]
|
||||||
|
|||||||
24
index.mjs
24
index.mjs
@@ -2,13 +2,20 @@ import { createServer } from 'node:http';
|
|||||||
import { clearInterval, setInterval } from 'node:timers';
|
import { clearInterval, setInterval } from 'node:timers';
|
||||||
|
|
||||||
const server = createServer((req, res) => {
|
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(
|
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 charIdx = 0;
|
||||||
let intervalId = setInterval(() => {
|
|
||||||
|
const intervalId = setInterval(() => {
|
||||||
if (charIdx === msg.length) {
|
if (charIdx === msg.length) {
|
||||||
charIdx = 0;
|
charIdx = 0;
|
||||||
res.write('\n');
|
res.write('\n');
|
||||||
@@ -17,7 +24,16 @@ const server = createServer((req, res) => {
|
|||||||
}
|
}
|
||||||
}, 3000);
|
}, 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);
|
server.listen(3000);
|
||||||
|
|||||||
Reference in New Issue
Block a user