Compare commits

..

10 Commits

3 changed files with 60 additions and 15 deletions

View File

@@ -2,6 +2,7 @@ FROM node:lts-alpine
USER node
WORKDIR /app
ENV NODE_ENV production
ENV TZ Europe/Warsaw
COPY --chown=node:node index.mjs ./
EXPOSE 3000
CMD ["node", "./index.mjs"]

24
LICENSE Normal file
View File

@@ -0,0 +1,24 @@
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <https://unlicense.org/>

View File

@@ -1,23 +1,43 @@
import { createServer } from 'node:http';
import { clearInterval, setInterval } from 'node:timers';
import { setTimeout } from 'node:timers';
const msg = 'Relax, take it easy! For there is nothing that we can do.';
const minDelay = 3000;
const maxDelay = 5000;
const delayDiff = maxDelay - minDelay;
const randomDelay = () => Math.floor(Math.random() * delayDiff + minDelay);
const server = createServer((req, res) => {
console.log(
`Caught ${req.headers['x-forwarded-for']} on ${req.method} ${req.url}`
);
let msg = ':) you are an idiot hahahahaha :)';
const connOpenDate = new Date();
const dateText = connOpenDate.toLocaleString('pl');
const scannerIP = req.headers['x-forwarded-for'];
const host = req.headers['x-forwarded-host'];
const endpoint = `${req.method} ${req.url}`;
let charIdx = 0;
let intervalId = setInterval(() => {
if (charIdx === msg.length) {
charIdx = 0;
res.write('\n');
} else {
res.write(msg[charIdx++]);
}
}, 3000);
res.once('close', () => clearInterval(intervalId));
console.log(`[${dateText}] ${scannerIP} targeted ${host} on ${endpoint}`);
const hang = () => {
if (res.closed) return;
else if (charIdx === msg.length) res.end('\n');
else res.write(msg[charIdx++]);
setTimeout(hang, randomDelay());
};
hang();
res.once('close', () => {
const connCloseDate = new Date();
const timeDiff = connCloseDate.getTime() - connOpenDate.getTime();
const dateText = connCloseDate.toLocaleString('pl');
const diffText = new Date(timeDiff).toISOString().substring(14, 19);
const hangResult =
charIdx === msg.length ? 'received the message' : 'aborted connection';
console.log(`[${dateText}] ${scannerIP} ${hangResult} after ${diffText}`);
});
});
server.listen(3000);