-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
124 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
paStash IP Port to Protocol filter (rust) | ||
--- | ||
|
||
Status : functional, experimental plugin. | ||
|
||
## IP Proto Filter | ||
|
||
Resolves a port number to IP protocol | ||
|
||
##### Example | ||
``` | ||
filter { | ||
ip_proto { | ||
source_field => l4_dst_port | ||
target_field => proto | ||
custom => "8883:mqtt,1194:ovpn" | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
Port to Protocol plugin for @pastash/pastash | ||
(C) 2024 QXIP BV | ||
*/ | ||
|
||
var base_filter = require('@pastash/pastash').base_filter, | ||
util = require('util'), | ||
logger = require('@pastash/pastash').logger; | ||
|
||
function FilterIPProto() { | ||
base_filter.BaseFilter.call(this); | ||
this.mergeConfig({ | ||
name: 'ip_proto', | ||
optional_params: ['target_field', 'custom'], | ||
host_field: 'source_field', | ||
debug: false, | ||
default_values: { | ||
'debug': false, | ||
'custom': false, | ||
}, | ||
start_hook: this.start.bind(this) | ||
}); | ||
} | ||
|
||
var ipProto = { | ||
1: "icmp", | ||
2: "igmp", | ||
6: "tcp", | ||
9: "egp", | ||
17: "udp", | ||
27: "rdp", | ||
41: "encap-v6", | ||
47: "gre", | ||
53: "dns", | ||
56: "tlsp", | ||
58: "icmp-v6", | ||
80: "http", | ||
89: "ospf", | ||
94: "ipip", | ||
123: "ntp", | ||
132: "sctp", | ||
443: "https", | ||
}; | ||
|
||
util.inherits(FilterIPProto, base_filter.BaseFilter); | ||
|
||
FilterIPProto.prototype.start = function(callback) { | ||
if (!this.target_field) { | ||
this.target_field = this.source_field; | ||
} | ||
if (this.custom) { | ||
var pairs = this.custom.split(','); | ||
pairs.forEach(pair => { | ||
let [ip, proto] = pair.split(':'); | ||
ipProto.push({ ip: parseInt(ip), proto: proto }); | ||
}); | ||
} | ||
|
||
logger.info('Initializing IP protocol filter from', this.source_field, 'to', this.target_field); | ||
callback(); | ||
}; | ||
|
||
FilterIPProto.prototype.process = function(data) { | ||
var x = parseInt(data[this.source_field]); | ||
if (x) { | ||
try { | ||
var result = ipProto[x]; | ||
if (result !== undefined && result !== null && (typeof result === 'string' || ! isNaN(result)) && result !== Infinity) { | ||
data[this.target_field] = result; | ||
} | ||
} | ||
catch(err) { | ||
} | ||
} | ||
return data; | ||
}; | ||
|
||
exports.create = function() { | ||
return new FilterIPProto(); | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"name": "@pastash/filter_ipproto", | ||
"version": "1.0.0", | ||
"description": "Port to Protocol plugin for @pastash/pastash", | ||
"main": "filter_ipproto.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "Lorenzo Mangani <[email protected]>", | ||
"license": "ISC", | ||
"dependencies": {} | ||
} |