Use ufw-log-parser
This commit is contained in:
1 parent
321cd89a1a
commit
9cc7be6dcc
4 files changed
+13
-26
No files matched your search
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
const fs = require('node:fs');
|
const fs = require('node:fs');
|
||||||
const chokidar = require('chokidar');
|
const chokidar = require('chokidar');
|
||||||
|
const { parseUfwLog } = require('ufw-log-parser');
|
||||||
const axios = require('./scripts/services/axios.js');
|
const axios = require('./scripts/services/axios.js');
|
||||||
const { saveBufferToFile, loadBufferFromFile, sendBulkReport, BULK_REPORT_BUFFER } = require('./scripts/services/bulk.js');
|
const { saveBufferToFile, loadBufferFromFile, sendBulkReport, BULK_REPORT_BUFFER } = require('./scripts/services/bulk.js');
|
||||||
const { reportedIPs, loadReportedIPs, saveReportedIPs, isIPReportedRecently, markIPAsReported } = require('./scripts/services/cache.js');
|
const { reportedIPs, loadReportedIPs, saveReportedIPs, isIPReportedRecently, markIPAsReported } = require('./scripts/services/cache.js');
|
||||||
@@ -10,7 +11,6 @@ const { refreshServerIPs, getServerIPs } = require('./scripts/services/ipFetcher
|
|||||||
const { version, repoName, repoURL } = require('./scripts/utils/repo.js');
|
const { version, repoName, repoURL } = require('./scripts/utils/repo.js');
|
||||||
const sendWebhook = require('./scripts/services/discordWebhooks.js');
|
const sendWebhook = require('./scripts/services/discordWebhooks.js');
|
||||||
const isLocalIP = require('./scripts/utils/isLocalIP.js');
|
const isLocalIP = require('./scripts/utils/isLocalIP.js');
|
||||||
const { parseNumber, parseTimestamp } = require('./scripts/utils/parse.js');
|
|
||||||
const log = require('./scripts/utils/log.js');
|
const log = require('./scripts/utils/log.js');
|
||||||
const config = require('./config.js');
|
const config = require('./config.js');
|
||||||
const { UFW_LOG_FILE, ABUSEIPDB_API_KEY, SERVER_ID, EXTENDED_LOGS, AUTO_UPDATE_ENABLED, AUTO_UPDATE_SCHEDULE, DISCORD_WEBHOOKS_ENABLED, DISCORD_WEBHOOKS_URL } = config.MAIN;
|
const { UFW_LOG_FILE, ABUSEIPDB_API_KEY, SERVER_ID, EXTENDED_LOGS, AUTO_UPDATE_ENABLED, AUTO_UPDATE_SCHEDULE, DISCORD_WEBHOOKS_ENABLED, DISCORD_WEBHOOKS_URL } = config.MAIN;
|
||||||
@@ -97,28 +97,7 @@ const reportIp = async ({ srcIp, dpt = 'N/A', proto = 'N/A', id, timestamp }, ca
|
|||||||
const processLogLine = async (line, test = false) => {
|
const processLogLine = async (line, test = false) => {
|
||||||
if (!line.includes('[UFW BLOCK]')) return log(`Ignoring invalid line: ${line}`, 2);
|
if (!line.includes('[UFW BLOCK]')) return log(`Ignoring invalid line: ${line}`, 2);
|
||||||
|
|
||||||
const data = {
|
const data = parseUfwLog(line);
|
||||||
timestamp: parseTimestamp(line),
|
|
||||||
srcIp: line.match(/SRC=(\S+)/)?.[1] || null,
|
|
||||||
dstIp: line.match(/DST=(\S+)/)?.[1] || null,
|
|
||||||
proto: line.match(/PROTO=(\S+)/)?.[1] || null,
|
|
||||||
spt: parseNumber(line, /SPT=(\d+)/),
|
|
||||||
dpt: parseNumber(line, /DPT=(\d+)/),
|
|
||||||
in: line.match(/IN=(\w+)/)?.[1] || null,
|
|
||||||
out: line.match(/OUT=(\w+)/)?.[1] || null,
|
|
||||||
mac: line.match(/MAC=([\w:]+)/)?.[1] || null,
|
|
||||||
len: parseNumber(line, /LEN=(\d+)/),
|
|
||||||
ttl: parseNumber(line, /TTL=(\d+)/),
|
|
||||||
id: parseNumber(line, /ID=(\d+)/),
|
|
||||||
tos: line.match(/TOS=(\S+)/)?.[1] || null,
|
|
||||||
prec: line.match(/PREC=(\S+)/)?.[1] || null,
|
|
||||||
res: line.match(/RES=(\S+)/)?.[1] || null,
|
|
||||||
window: parseNumber(line, /WINDOW=(\d+)/),
|
|
||||||
urgp: parseNumber(line, /URGP=(\d+)/),
|
|
||||||
ack: !!line.includes('ACK'),
|
|
||||||
syn: !!line.includes('SYN'),
|
|
||||||
};
|
|
||||||
|
|
||||||
const { srcIp, proto, dpt } = data;
|
const { srcIp, proto, dpt } = data;
|
||||||
if (!srcIp) return log(`Missing SRC in the log line: ${line}`, 3);
|
if (!srcIp) return log(`Missing SRC in the log line: ${line}`, 3);
|
||||||
|
|
||||||
|
|||||||
Generated
+8
-1
@@ -16,7 +16,8 @@
|
|||||||
"csv-stringify": "^6.5.2",
|
"csv-stringify": "^6.5.2",
|
||||||
"form-data": "^4.0.2",
|
"form-data": "^4.0.2",
|
||||||
"ipaddr.js": "^2.2.0",
|
"ipaddr.js": "^2.2.0",
|
||||||
"simple-git": "^3.27.0"
|
"simple-git": "^3.27.0",
|
||||||
|
"ufw-log-parser": "^0.1.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@eslint/js": "^9.25.1",
|
"@eslint/js": "^9.25.1",
|
||||||
@@ -453,6 +454,12 @@
|
|||||||
"type": "github",
|
"type": "github",
|
||||||
"url": "https://github.com/steveukx/git-js?sponsor=1"
|
"url": "https://github.com/steveukx/git-js?sponsor=1"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"node_modules/ufw-log-parser": {
|
||||||
|
"version": "0.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/ufw-log-parser/-/ufw-log-parser-0.1.0.tgz",
|
||||||
|
"integrity": "sha512-0hPoehTmx7bHWSGfl2ieFs4YeNRGRv1xdfFTToZeHWSNz+hUwQ0aK2h0VqeEaVMcxKGkj2DFIY8L5NqnpBwcWg==",
|
||||||
|
"license": "MIT"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+2
-1
@@ -27,7 +27,8 @@
|
|||||||
"csv-stringify": "^6.5.2",
|
"csv-stringify": "^6.5.2",
|
||||||
"form-data": "^4.0.2",
|
"form-data": "^4.0.2",
|
||||||
"ipaddr.js": "^2.2.0",
|
"ipaddr.js": "^2.2.0",
|
||||||
"simple-git": "^3.27.0"
|
"simple-git": "^3.27.0",
|
||||||
|
"ufw-log-parser": "^0.1.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@eslint/js": "^9.25.1",
|
"@eslint/js": "^9.25.1",
|
||||||
|
|||||||
+1
-1
Submodule scripts updated: 01708ade43...7ded8c8742.
Reference in new issue
Block a user