improves on the nfregex binary x5
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -25,7 +25,7 @@ docker-compose.yml
|
|||||||
firegex-compose.yml
|
firegex-compose.yml
|
||||||
firegex-compose-tmp-file.yml
|
firegex-compose-tmp-file.yml
|
||||||
firegex.py
|
firegex.py
|
||||||
|
/tests/benchmark.csv
|
||||||
# misc
|
# misc
|
||||||
**/.DS_Store
|
**/.DS_Store
|
||||||
**/.env.local
|
**/.env.local
|
||||||
|
|||||||
@@ -438,7 +438,6 @@ class NetfilterQueue {
|
|||||||
cerr << "[DEBUG] [NetfilterQueue.queue_cb] Packet received" << endl;
|
cerr << "[DEBUG] [NetfilterQueue.queue_cb] Packet received" << endl;
|
||||||
cerr << "[DEBUG] [NetfilterQueue.queue_cb] Packet ID: " << ntohl(ph->packet_id) << endl;
|
cerr << "[DEBUG] [NetfilterQueue.queue_cb] Packet ID: " << ntohl(ph->packet_id) << endl;
|
||||||
cerr << "[DEBUG] [NetfilterQueue.queue_cb] Payload size: " << plen << endl;
|
cerr << "[DEBUG] [NetfilterQueue.queue_cb] Payload size: " << plen << endl;
|
||||||
cerr << "[DEBUG] [NetfilterQueue.queue_cb] Payload: " << string(payload, payload+plen) << endl;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Check IP protocol version
|
// Check IP protocol version
|
||||||
|
|||||||
@@ -72,10 +72,12 @@ bool filter_callback(packet_info& info){
|
|||||||
if (regex_matcher == nullptr){
|
if (regex_matcher == nullptr){
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
cerr << "[DEBUG] [filter_callback] Matching packet with " << (info.is_input ? "input" : "output") << " ruleset" << endl;
|
cerr << "[DEBUG] [filter_callback] Matching packet with " << (info.is_input ? "input" : "output") << " ruleset" << endl;
|
||||||
cerr << "[DEBUG] [filter_callback] Packet: " << info.payload << endl;
|
if (info.payload.size() <= 30){
|
||||||
|
cerr << "[DEBUG] [filter_callback] Packet: " << info.payload << endl;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
matched_data match_res;
|
matched_data match_res;
|
||||||
@@ -153,14 +155,14 @@ int main(int argc, char *argv[]){
|
|||||||
if (matchmode != nullptr && strcmp(matchmode, "block") == 0){
|
if (matchmode != nullptr && strcmp(matchmode, "block") == 0){
|
||||||
stream_mode = false;
|
stream_mode = false;
|
||||||
}
|
}
|
||||||
cerr << "[info] [main] Using " << n_of_threads << " threads, stream mode: " << stream_mode << endl;
|
|
||||||
regex_config.reset(new RegexRules(stream_mode));
|
regex_config.reset(new RegexRules(stream_mode));
|
||||||
|
|
||||||
NFQueueSequence<filter_callback> queues(n_of_threads);
|
NFQueueSequence<filter_callback> queues(n_of_threads);
|
||||||
queues.start();
|
queues.start();
|
||||||
|
|
||||||
cout << "QUEUES " << queues.init() << " " << queues.end() << endl;
|
cout << "QUEUES " << queues.init() << " " << queues.end() << endl;
|
||||||
cerr << "[info] [main] Queues: " << queues.init() << ":" << queues.end() << " threads assigned: " << n_of_threads << endl;
|
cerr << "[info] [main] Queues: " << queues.init() << ":" << queues.end() << " threads assigned: " << n_of_threads << " stream mode: " << stream_mode << endl;
|
||||||
|
|
||||||
config_updater();
|
config_updater();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Button, Group, Space, TextInput, Notification, Switch, NativeSelect, Modal } from '@mantine/core';
|
import { Button, Group, Space, TextInput, Notification, Switch, Modal, Select } from '@mantine/core';
|
||||||
import { useForm } from '@mantine/form';
|
import { useForm } from '@mantine/form';
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { RegexAddForm } from '../js/models';
|
import { RegexAddForm } from '../js/models';
|
||||||
@@ -17,13 +17,13 @@ function AddNewRegex({ opened, onClose, service }:{ opened:boolean, onClose:()=>
|
|||||||
const form = useForm({
|
const form = useForm({
|
||||||
initialValues: {
|
initialValues: {
|
||||||
regex:"",
|
regex:"",
|
||||||
mode:"C -> S",
|
mode:"C",
|
||||||
is_case_insensitive:false,
|
is_case_insensitive:false,
|
||||||
deactive:false
|
deactive:false
|
||||||
},
|
},
|
||||||
validate:{
|
validate:{
|
||||||
regex: (value) => value !== "" ? null : "Regex is required",
|
regex: (value) => value !== "" ? null : "Regex is required",
|
||||||
mode: (value) => ['C -> S', 'S -> C', 'C <-> S'].includes(value) ? null : "Invalid mode",
|
mode: (value) => ['C', 'S', 'B'].includes(value) ? null : "Invalid mode",
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -38,12 +38,11 @@ function AddNewRegex({ opened, onClose, service }:{ opened:boolean, onClose:()=>
|
|||||||
|
|
||||||
const submitRequest = (values:RegexAddInfo) => {
|
const submitRequest = (values:RegexAddInfo) => {
|
||||||
setSubmitLoading(true)
|
setSubmitLoading(true)
|
||||||
const filter_mode = ({'C -> S':'C', 'S -> C':'S', 'C <-> S':'B'}[values.mode])
|
|
||||||
|
|
||||||
const request:RegexAddForm = {
|
const request:RegexAddForm = {
|
||||||
is_case_sensitive: !values.is_case_insensitive,
|
is_case_sensitive: !values.is_case_insensitive,
|
||||||
service_id: service,
|
service_id: service,
|
||||||
mode: filter_mode?filter_mode:"B",
|
mode: values.mode?values.mode:"B",
|
||||||
regex: b64encode(values.regex),
|
regex: b64encode(values.regex),
|
||||||
active: !values.deactive
|
active: !values.deactive
|
||||||
}
|
}
|
||||||
@@ -86,8 +85,12 @@ function AddNewRegex({ opened, onClose, service }:{ opened:boolean, onClose:()=>
|
|||||||
{...form.getInputProps('deactive', { type: 'checkbox' })}
|
{...form.getInputProps('deactive', { type: 'checkbox' })}
|
||||||
/>
|
/>
|
||||||
<Space h="md" />
|
<Space h="md" />
|
||||||
<NativeSelect
|
<Select
|
||||||
data={['C -> S', 'S -> C', 'C <-> S']}
|
data={[
|
||||||
|
{ value: 'C', label: 'Client -> Server' },
|
||||||
|
{ value: 'S', label: 'Server -> Client' },
|
||||||
|
{ value: 'B', label: 'Both (Client <-> Server)' },
|
||||||
|
]}
|
||||||
label="Choose the source of the packets to filter"
|
label="Choose the source of the packets to filter"
|
||||||
variant="filled"
|
variant="filled"
|
||||||
{...form.getInputProps('mode')}
|
{...form.getInputProps('mode')}
|
||||||
|
|||||||
@@ -9,8 +9,6 @@ import argparse
|
|||||||
import base64
|
import base64
|
||||||
import secrets
|
import secrets
|
||||||
|
|
||||||
|
|
||||||
#TODO: make it work with Proxy and not only netfilter
|
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument("--address", "-a", type=str , required=False, help='Address of firegex backend', default="http://127.0.0.1:4444/")
|
parser.add_argument("--address", "-a", type=str , required=False, help='Address of firegex backend', default="http://127.0.0.1:4444/")
|
||||||
parser.add_argument("--port", "-P", type=int , required=False, help='Port of the Benchmark service', default=1337)
|
parser.add_argument("--port", "-P", type=int , required=False, help='Port of the Benchmark service', default=1337)
|
||||||
|
|||||||
Reference in New Issue
Block a user