venus-pit 1.1.6 → 1.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/venus.bundle.js +2 -2
- package/dist/venus.bundle.js.map +1 -1
- package/package.json +3 -2
- package/src/lib/tarpit/corpora.js +2 -2
- package/src/lib/tarpit/markov.js +18 -19
- package/src/lib/tarpit/pit.js +52 -46
- package/src/lib/tarpit/tar.js +12 -11
- package/src/lib/tarpit/words/randomWord.js +9 -7
- package/src/lib/venusRoot.js +17 -13
- package/src/venus.js +14 -12
- package/testing/venus.js +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "venus-pit",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.7",
|
|
4
4
|
"description": "Express.js-based tarpit",
|
|
5
5
|
"main": "dist/venus.bundle.js",
|
|
6
6
|
"type": "module",
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@rspack/cli": "^1.6.0",
|
|
23
|
-
"node-html-parser": "^7.0.1"
|
|
23
|
+
"node-html-parser": "^7.0.1",
|
|
24
|
+
"prettier": "^3.7.4"
|
|
24
25
|
}
|
|
25
26
|
}
|
|
@@ -2643,6 +2643,6 @@ question, now, what had happened to the faces of the pigs. The
|
|
|
2643
2643
|
creatures outside looked from pig to man, and from man to pig, and
|
|
2644
2644
|
from pig to man again; but already it was impossible to say which was
|
|
2645
2645
|
which.
|
|
2646
|
-
|
|
2646
|
+
`;
|
|
2647
2647
|
|
|
2648
|
-
export default corpora
|
|
2648
|
+
export default corpora;
|
package/src/lib/tarpit/markov.js
CHANGED
|
@@ -1,26 +1,25 @@
|
|
|
1
1
|
function markov(corpus, max) {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
const words = corpus.split(/\s+/);
|
|
3
|
+
const transitions = {};
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
5
|
+
for (let i = 0; i < words.length - 1; i++) {
|
|
6
|
+
const word = words[i];
|
|
7
|
+
const nextWord = words[i + 1];
|
|
8
|
+
if (!transitions[word]) transitions[word] = [];
|
|
9
|
+
transitions[word].push(nextWord);
|
|
10
|
+
}
|
|
12
11
|
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
let current = words[Math.floor(Math.random() * words.length)];
|
|
13
|
+
let output = [current];
|
|
15
14
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
for (let i = 1; i < max; i++) {
|
|
16
|
+
const nextWords = transitions[current];
|
|
17
|
+
if (!nextWords || nextWords.length === 0) break;
|
|
18
|
+
current = nextWords[Math.floor(Math.random() * nextWords.length)];
|
|
19
|
+
output.push(current);
|
|
20
|
+
}
|
|
22
21
|
|
|
23
|
-
|
|
22
|
+
return output.join(" ");
|
|
24
23
|
}
|
|
25
24
|
|
|
26
|
-
export default markov
|
|
25
|
+
export default markov;
|
package/src/lib/tarpit/pit.js
CHANGED
|
@@ -1,62 +1,68 @@
|
|
|
1
|
-
import { tar } from "./tar.js"
|
|
2
|
-
import express from
|
|
3
|
-
import {randomWord} from "./words/randomWord.js"
|
|
1
|
+
import { tar } from "./tar.js";
|
|
2
|
+
import express from "express";
|
|
3
|
+
import { randomWord } from "./words/randomWord.js";
|
|
4
4
|
|
|
5
5
|
function rand() {
|
|
6
|
-
|
|
6
|
+
return (Math.sqrt(Math.random() * 10) / 2) * 1000;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
const tarpitRouter = express.Router();
|
|
10
|
-
const routeHandlers = new Map();
|
|
10
|
+
const routeHandlers = new Map();
|
|
11
11
|
let inited = false;
|
|
12
12
|
|
|
13
13
|
function makeRoute() {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
14
|
+
let length = Math.floor(Math.sqrt(Math.random()) * 10);
|
|
15
|
+
length = Math.max(length, 1)
|
|
16
|
+
let words = "";
|
|
17
|
+
for (let i = 0; i < length; i++) {
|
|
18
|
+
let word = randomWord();
|
|
19
|
+
words = words + word + "-";
|
|
20
|
+
}
|
|
21
|
+
if (words.endsWith("-")) words = words.slice(0, -1);
|
|
22
|
+
return words;
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
function selfDestruct(route) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
26
|
+
if (routeHandlers.has(route)) {
|
|
27
|
+
routeHandlers.delete(route);
|
|
28
|
+
|
|
29
|
+
// recreate the router w/o the deleted route
|
|
30
|
+
tarpitRouter.stack = tarpitRouter.stack.filter((layer) => {
|
|
31
|
+
return !(layer.route && layer.route.path === route);
|
|
32
|
+
});
|
|
33
|
+
}
|
|
32
34
|
}
|
|
33
35
|
|
|
34
36
|
function pit(app, instanceRoot, req) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
37
|
+
let newRoute = `${instanceRoot.path}${makeRoute()}/`;
|
|
38
|
+
console.log(`Creating route ${newRoute} for UA ${req.headers["user-agent"]}`);
|
|
39
|
+
|
|
40
|
+
const handler = (req, res) => {
|
|
41
|
+
// use a promise to avoid a stack overflow
|
|
42
|
+
Promise.resolve().then(() => {
|
|
43
|
+
// reasonable server response time, should waste cpu cycles
|
|
44
|
+
setTimeout(() => {
|
|
45
|
+
res.send(tar(pit(app, instanceRoot, req)));
|
|
46
|
+
}, rand());
|
|
47
|
+
|
|
48
|
+
// prevent memory leak by cleaning up old routes : add delay on garbage collection
|
|
49
|
+
setTimeout(() => {
|
|
50
|
+
selfDestruct(newRoute);
|
|
51
|
+
}, rand() * rand());
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
routeHandlers.set(newRoute, handler);
|
|
56
|
+
tarpitRouter.get(newRoute, handler);
|
|
57
|
+
// FOR TESTIng PURPOSES IF THIS MAKES IT TO PROD JUTS SHOOT ME
|
|
58
|
+
//fetch(`http://localhost:8080${newRoute}`)
|
|
59
|
+
|
|
60
|
+
// just so it doesnt get attached multiple times
|
|
61
|
+
if (!inited) {
|
|
62
|
+
app.use(tarpitRouter);
|
|
63
|
+
inited = true;
|
|
64
|
+
}
|
|
65
|
+
return newRoute;
|
|
60
66
|
}
|
|
61
67
|
|
|
62
|
-
export { pit }
|
|
68
|
+
export { pit };
|
package/src/lib/tarpit/tar.js
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
// see /docs/tar.md
|
|
1
|
+
// see /docs/tar.md
|
|
2
2
|
|
|
3
|
-
import markov from "./markov.js"
|
|
4
|
-
import corpora from "./corpora.js"
|
|
3
|
+
import markov from "./markov.js";
|
|
4
|
+
import corpora from "./corpora.js";
|
|
5
5
|
|
|
6
6
|
function tar(route) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
let title, header;
|
|
8
|
+
title = header = markov(corpora, 2);
|
|
9
|
+
let link = markov(corpora, Math.floor(Math.random() * 10) + 1);
|
|
10
|
+
let content = markov(corpora, 50);
|
|
11
|
+
return `
|
|
11
12
|
<head>
|
|
12
13
|
<title>${title}</title>
|
|
13
|
-
<meta name="description" content=${markov(corpora, Math.floor(Math.random()*10))}></meta>
|
|
14
|
+
<meta name="description" content=${markov(corpora, Math.floor(Math.random() * 10))}></meta>
|
|
14
15
|
</head>
|
|
15
16
|
<body>
|
|
16
17
|
<h1>${header}</h1><br/>
|
|
@@ -25,10 +26,10 @@ function tar(route) {
|
|
|
25
26
|
}
|
|
26
27
|
console.log(result)
|
|
27
28
|
let y = new Array(400*2024*10).fill(0)
|
|
28
|
-
document.getElementById("realContent").innerText = "${markov(corpora, 50+Math.floor(Math.random()*10))}"
|
|
29
|
+
document.getElementById("realContent").innerText = "${markov(corpora, 50 + Math.floor(Math.random() * 10))}"
|
|
29
30
|
</script>
|
|
30
31
|
</body>
|
|
31
|
-
|
|
32
|
+
`;
|
|
32
33
|
}
|
|
33
34
|
|
|
34
|
-
export { tar }
|
|
35
|
+
export { tar };
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import corpora from "../corpora.js"
|
|
2
|
-
import crypto from
|
|
1
|
+
import corpora from "../corpora.js";
|
|
2
|
+
import crypto from "crypto";
|
|
3
3
|
|
|
4
4
|
// remove all non a-z, lowercase, split into tokens
|
|
5
|
-
let wordList = corpora
|
|
5
|
+
let wordList = corpora
|
|
6
|
+
.replace(/[^a-zA-Z ]/g, "")
|
|
7
|
+
.toLowerCase()
|
|
8
|
+
.split(/\s+/); // more efficient to just compute once
|
|
6
9
|
function randomWord() {
|
|
7
|
-
|
|
8
|
-
|
|
10
|
+
const index = crypto.randomInt(0, wordList.length);
|
|
11
|
+
return wordList[index];
|
|
9
12
|
}
|
|
10
13
|
|
|
11
|
-
|
|
12
|
-
export {randomWord}
|
|
14
|
+
export { randomWord };
|
package/src/lib/venusRoot.js
CHANGED
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
// venus root path : the 32 char long random lowercase letters
|
|
2
2
|
class venusRoot {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
3
|
+
constructor(venusRoot = "UNSET") {
|
|
4
|
+
if (venusRoot == "UNSET") {
|
|
5
|
+
const alphabetLowercase = "abcdefghijklmnopqrstuvwxyz";
|
|
6
|
+
this._venusRootCache = Array.from(
|
|
7
|
+
{ length: 32 },
|
|
8
|
+
() =>
|
|
9
|
+
alphabetLowercase[
|
|
10
|
+
Math.floor(Math.random() * alphabetLowercase.length)
|
|
11
|
+
],
|
|
12
|
+
).join("");
|
|
13
|
+
} else {
|
|
14
|
+
this._venusRootCache = venusRoot;
|
|
15
15
|
}
|
|
16
|
+
}
|
|
17
|
+
get path() {
|
|
18
|
+
return "/" + this._venusRootCache + "/";
|
|
19
|
+
}
|
|
16
20
|
}
|
|
17
21
|
|
|
18
|
-
export { venusRoot }
|
|
22
|
+
export { venusRoot };
|
package/src/venus.js
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
|
-
import { venusRoot } from
|
|
2
|
-
import {pit} from "./lib/tarpit/pit.js"
|
|
3
|
-
import { tar } from "./lib/tarpit/tar.js"
|
|
1
|
+
import { venusRoot } from "./lib/venusRoot.js";
|
|
2
|
+
import { pit } from "./lib/tarpit/pit.js";
|
|
3
|
+
import { tar } from "./lib/tarpit/tar.js";
|
|
4
4
|
|
|
5
|
-
function venus(app, root="UNSET") {
|
|
5
|
+
function venus(app, root = "UNSET") {
|
|
6
6
|
const instanceRoot = new venusRoot(root);
|
|
7
|
-
console.log(
|
|
8
|
-
app.set(
|
|
7
|
+
console.log("path: " + instanceRoot.path);
|
|
8
|
+
app.set("trust proxy", true); // fix ip detection
|
|
9
9
|
app.get(instanceRoot.path, (req, res) => {
|
|
10
|
-
let firsturl = pit(app, instanceRoot, req) // this will start the recursive hell known as a tarpit
|
|
11
|
-
res.send(tar(firsturl))
|
|
12
|
-
console.log(
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
let firsturl = pit(app, instanceRoot, req); // this will start the recursive hell known as a tarpit
|
|
11
|
+
res.send(tar(firsturl));
|
|
12
|
+
console.log(
|
|
13
|
+
`Creating tarpit for:\nuser-agent- ${req.headers["user-agent"]}\nIP- ${req.ip}`,
|
|
14
|
+
);
|
|
15
|
+
});
|
|
16
|
+
return instanceRoot.path;
|
|
15
17
|
}
|
|
16
18
|
|
|
17
|
-
export default venus
|
|
19
|
+
export default venus;
|