honeyweb-core 1.0.0
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/blocked-ips.json +0 -0
- package/index V1.js +85 -0
- package/index.js +113 -0
- package/package.json +18 -0
package/blocked-ips.json
ADDED
|
File without changes
|
package/index V1.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// honeyweb-core/index.js
|
|
2
|
+
const fs = require('fs-extra');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const cheerio = require('cheerio');
|
|
5
|
+
|
|
6
|
+
// File path for storing banned IPs automatically
|
|
7
|
+
const DB_FILE = path.join(__dirname, 'blocked-ips.json');
|
|
8
|
+
|
|
9
|
+
// Ensure the JSON file exists on startup
|
|
10
|
+
if (!fs.existsSync(DB_FILE)) {
|
|
11
|
+
fs.writeJsonSync(DB_FILE, []);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// Configuration: List of fake trap paths
|
|
15
|
+
// These look like real admin pages to a bot
|
|
16
|
+
const TRAP_PATHS = [
|
|
17
|
+
'/admin-backup-v2',
|
|
18
|
+
'/wp-login-hidden',
|
|
19
|
+
'/db-dump-2024',
|
|
20
|
+
'/auth/root-access',
|
|
21
|
+
'/sys/config-safe'
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* HoneyWeb Middleware
|
|
26
|
+
* Usage: app.use(honeyWeb());
|
|
27
|
+
*/
|
|
28
|
+
function honeyWeb() {
|
|
29
|
+
return async (req, res, next) => {
|
|
30
|
+
const clientIP = req.ip || req.connection.remoteAddress;
|
|
31
|
+
|
|
32
|
+
// 1. LOAD BANNED LIST
|
|
33
|
+
let bannedIPs = [];
|
|
34
|
+
try {
|
|
35
|
+
bannedIPs = await fs.readJson(DB_FILE);
|
|
36
|
+
} catch (err) {
|
|
37
|
+
console.error("HoneyWeb: Error reading blocklist", err);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// 2. CHECK IF IP IS ALREADY BANNED
|
|
41
|
+
if (bannedIPs.includes(clientIP)) {
|
|
42
|
+
console.log(`[HoneyWeb] BLOCKED access from banned IP: ${clientIP}`);
|
|
43
|
+
return res.status(403).send('<h1>403 Forbidden</h1><p>Your IP has been flagged for suspicious activity.</p>');
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// 3. CHECK IF TRAP ACCESSED
|
|
47
|
+
if (TRAP_PATHS.includes(req.path)) {
|
|
48
|
+
console.log(`[HoneyWeb] 🚨 TRAP TRIGGERED by ${clientIP} on ${req.path}`);
|
|
49
|
+
|
|
50
|
+
// Ban the IP immediately
|
|
51
|
+
if (!bannedIPs.includes(clientIP)) {
|
|
52
|
+
bannedIPs.push(clientIP);
|
|
53
|
+
await fs.writeJson(DB_FILE, bannedIPs);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return res.status(403).send('<h1>403 Forbidden</h1><p>You have accessed a restricted area.</p>');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// 4. INJECT TRAPS INTO HTML RESPONSES
|
|
60
|
+
const originalSend = res.send;
|
|
61
|
+
|
|
62
|
+
res.send = function (body) {
|
|
63
|
+
// Only inject if the content is HTML
|
|
64
|
+
if (typeof body === 'string' && (body.includes('<html') || body.includes('<body'))) {
|
|
65
|
+
const $ = cheerio.load(body);
|
|
66
|
+
|
|
67
|
+
// Pick a random trap
|
|
68
|
+
const trapUrl = TRAP_PATHS[Math.floor(Math.random() * TRAP_PATHS.length)];
|
|
69
|
+
|
|
70
|
+
// Create invisible link (Hidden by CSS)
|
|
71
|
+
const trapLink = `<a href="${trapUrl}" style="opacity:0; position:absolute; z-index:-999; left:-9999px;">Admin Panel</a>`;
|
|
72
|
+
|
|
73
|
+
// Inject into body
|
|
74
|
+
$('body').append(trapLink);
|
|
75
|
+
|
|
76
|
+
body = $.html();
|
|
77
|
+
}
|
|
78
|
+
originalSend.call(this, body);
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
next();
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
module.exports = honeyWeb;
|
package/index.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// honeyweb-core/index.js
|
|
2
|
+
const fs = require('fs-extra');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const cheerio = require('cheerio');
|
|
5
|
+
const { GoogleGenerativeAI } = require("@google/generative-ai");
|
|
6
|
+
|
|
7
|
+
const DB_FILE = path.join(__dirname, 'blocked-ips.json');
|
|
8
|
+
|
|
9
|
+
// ------------------------------------------------------
|
|
10
|
+
// CONFIGURATION
|
|
11
|
+
// ------------------------------------------------------
|
|
12
|
+
// ⚠️ PASTE YOUR GOOGLE API KEY HERE
|
|
13
|
+
const GOOGLE_API_KEY = 'YOUR_GOOGLE_API_KEY_HERE';
|
|
14
|
+
|
|
15
|
+
const TRAP_PATHS = [
|
|
16
|
+
'/admin-backup-v2',
|
|
17
|
+
'/wp-login-hidden',
|
|
18
|
+
'/db-dump-2024',
|
|
19
|
+
'/auth/root-access',
|
|
20
|
+
'/sys/config-safe'
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
if (!fs.existsSync(DB_FILE)) { fs.writeJsonSync(DB_FILE, []); }
|
|
24
|
+
|
|
25
|
+
// ------------------------------------------------------
|
|
26
|
+
// AI REPORTING FUNCTION
|
|
27
|
+
// ------------------------------------------------------
|
|
28
|
+
async function generateThreatReport(ip, userAgent, trapPath) {
|
|
29
|
+
// If you haven't pasted the key yet, skip AI to prevent crash
|
|
30
|
+
if (GOOGLE_API_KEY === 'YOUR_GOOGLE_API_KEY_HERE') {
|
|
31
|
+
console.log("⚠️ [HoneyWeb] No Google API Key found. Skipping AI Report.");
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
console.log("🤖 [HoneyWeb] Asking Gemini to analyze the attack...");
|
|
36
|
+
|
|
37
|
+
try {
|
|
38
|
+
const genAI = new GoogleGenerativeAI(GOOGLE_API_KEY);
|
|
39
|
+
|
|
40
|
+
const model = genAI.getGenerativeModel({ model: "gemini-2.5-flash" });
|
|
41
|
+
|
|
42
|
+
const prompt = `
|
|
43
|
+
You are a cybersecurity analyst. Analyze this bot attack caught by a honeypot.
|
|
44
|
+
|
|
45
|
+
Attack Details:
|
|
46
|
+
- IP Address: ${ip}
|
|
47
|
+
- User-Agent: ${userAgent}
|
|
48
|
+
- Trap Link Accessed: ${trapPath}
|
|
49
|
+
|
|
50
|
+
Please provide a 1-sentence summary of what kind of threat this is (e.g., reconnaissance, targeted scan) and what they were likely looking for.
|
|
51
|
+
`;
|
|
52
|
+
|
|
53
|
+
const result = await model.generateContent(prompt);
|
|
54
|
+
const report = result.response.text();
|
|
55
|
+
|
|
56
|
+
console.log("\n📝 [HoneyWeb INTELLIGENCE REPORT]");
|
|
57
|
+
console.log("---------------------------------------------------");
|
|
58
|
+
console.log(report.trim());
|
|
59
|
+
console.log("---------------------------------------------------\n");
|
|
60
|
+
|
|
61
|
+
} catch (error) {
|
|
62
|
+
// Detailed error logging to help you debug
|
|
63
|
+
console.error("❌ [HoneyWeb] Gemini Analysis Failed:", error.message);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// ------------------------------------------------------
|
|
68
|
+
// MIDDLEWARE LOGIC
|
|
69
|
+
// ------------------------------------------------------
|
|
70
|
+
function honeyWeb() {
|
|
71
|
+
return async (req, res, next) => {
|
|
72
|
+
const clientIP = req.ip || req.connection.remoteAddress;
|
|
73
|
+
|
|
74
|
+
// 1. Check Blocklist
|
|
75
|
+
let bannedIPs = [];
|
|
76
|
+
try { bannedIPs = await fs.readJson(DB_FILE); } catch (e) {}
|
|
77
|
+
|
|
78
|
+
if (bannedIPs.includes(clientIP)) {
|
|
79
|
+
return res.status(403).send('<h1>403 Forbidden</h1><p>Banned by HoneyWeb.</p>');
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// 2. Check Trap
|
|
83
|
+
if (TRAP_PATHS.includes(req.path)) {
|
|
84
|
+
console.log(`[HoneyWeb] 🚨 TRAP TRIGGERED by ${clientIP}`);
|
|
85
|
+
|
|
86
|
+
if (!bannedIPs.includes(clientIP)) {
|
|
87
|
+
bannedIPs.push(clientIP);
|
|
88
|
+
await fs.writeJson(DB_FILE, bannedIPs);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Trigger AI Analysis
|
|
92
|
+
generateThreatReport(clientIP, req.headers['user-agent'], req.path);
|
|
93
|
+
|
|
94
|
+
return res.status(403).send('<h1>403 Forbidden</h1>');
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// 3. Inject Hidden Links
|
|
98
|
+
const originalSend = res.send;
|
|
99
|
+
res.send = function (body) {
|
|
100
|
+
if (typeof body === 'string' && (body.includes('<html') || body.includes('<body'))) {
|
|
101
|
+
const $ = cheerio.load(body);
|
|
102
|
+
const trapUrl = TRAP_PATHS[Math.floor(Math.random() * TRAP_PATHS.length)];
|
|
103
|
+
$('body').append(`<a href="${trapUrl}" style="opacity:0; position:absolute; z-index:-999;">Admin</a>`);
|
|
104
|
+
body = $.html();
|
|
105
|
+
}
|
|
106
|
+
originalSend.call(this, body);
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
next();
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
module.exports = honeyWeb;
|
package/package.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "honeyweb-core",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
+
},
|
|
9
|
+
"keywords": [],
|
|
10
|
+
"author": "",
|
|
11
|
+
"license": "ISC",
|
|
12
|
+
"type": "commonjs",
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@google/generative-ai": "^0.24.1",
|
|
15
|
+
"cheerio": "^1.2.0",
|
|
16
|
+
"fs-extra": "^11.3.3"
|
|
17
|
+
}
|
|
18
|
+
}
|