Frontend Changes

This commit is contained in:
DomySh
2022-06-22 01:31:46 +02:00
parent ede11873c5
commit 34d6b18ec0
10 changed files with 69 additions and 65 deletions

View File

@@ -295,11 +295,8 @@ def post_regexes_add():
"is_case_sensitive" : {"type" : "boolean"}
},
})
if not re.match("^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)?$",req["regex"]):
return abort(400)
except Exception:
return abort(400)
try:
re.compile(b64decode(req["regex"]))
except Exception:

View File

@@ -39,10 +39,10 @@ unhexlify(InputIterator first, InputIterator last, OutputIterator ascii) {
return 0;
}
vector<pair<string,std::regex>> regex_s_c_w, regex_c_s_w, regex_s_c_b, regex_c_s_b;
vector<pair<string,regex>> regex_s_c_w, regex_c_s_w, regex_s_c_b, regex_c_s_b;
const char* config_file;
bool filter_data(unsigned char* data, const size_t& bytes_transferred, vector<pair<string,std::regex>> const &blacklist, vector<pair<string,std::regex>> const &whitelist){
bool filter_data(unsigned char* data, const size_t& bytes_transferred, vector<pair<string,regex>> const &blacklist, vector<pair<string,regex>> const &whitelist){
#ifdef DEBUG
cout << "---------------- Packet ----------------" << endl;
for(int i=0;i<bytes_transferred;i++){
@@ -50,32 +50,28 @@ bool filter_data(unsigned char* data, const size_t& bytes_transferred, vector<pa
}
cout << "\n" << "---------------- End Packet ----------------" << endl;
#endif
for (pair<string,std::regex> ele:blacklist){
std::cmatch what;
for (pair<string,regex> ele:blacklist){
cmatch what;
try{
std::regex_search(reinterpret_cast<const char*>(data), what, ele.second);
regex_search(reinterpret_cast<const char*>(data), what, ele.second);
if(what.size() > 0){
cout << "BLOCKED " << ele.first << endl;
return false;
}
} catch(...){
#ifdef DEBUG
cerr << "Error while matching regex: " << ele.first << endl;
#endif
}
}
for (pair<string,std::regex> ele:whitelist){
std::cmatch what;
for (pair<string,regex> ele:whitelist){
cmatch what;
try{
std::regex_search(reinterpret_cast<const char*>(data), what, ele.second);
regex_search(reinterpret_cast<const char*>(data), what, ele.second);
if(what.size() < 0){
cout << "BLOCKED " << ele.first << endl;
return false;
}
} catch(...){
#ifdef DEBUG
cerr << "Error while matching regex: " << ele.first << endl;
#endif
}
}
#ifdef DEBUG
@@ -112,7 +108,7 @@ namespace tcp_proxy
return upstream_socket_;
}
void start(const std::string& upstream_host, unsigned short upstream_port)
void start(const string& upstream_host, unsigned short upstream_port)
{
// Attempt connection to remote server (upstream side)
upstream_socket_.async_connect(
@@ -266,8 +262,8 @@ namespace tcp_proxy
public:
acceptor(boost::asio::io_service& io_service,
const std::string& local_host, unsigned short local_port,
const std::string& upstream_host, unsigned short upstream_port)
const string& local_host, unsigned short local_port,
const string& upstream_host, unsigned short upstream_port)
: io_service_(io_service),
localhost_address(boost::asio::ip::address_v4::from_string(local_host)),
acceptor_(io_service_,ip::tcp::endpoint(localhost_address,local_port)),
@@ -286,9 +282,9 @@ namespace tcp_proxy
this,
boost::asio::placeholders::error));
}
catch(std::exception& e)
catch(exception& e)
{
std::cerr << "acceptor exception: " << e.what() << std::endl;
cerr << "acceptor exception: " << e.what() << endl;
return false;
}
@@ -305,12 +301,12 @@ namespace tcp_proxy
if (!accept_connections())
{
std::cerr << "Failure during call to accept." << std::endl;
cerr << "Failure during call to accept." << endl;
}
}
else
{
std::cerr << "Error: " << error.message() << std::endl;
cerr << "Error: " << error.message() << endl;
}
}
@@ -319,33 +315,33 @@ namespace tcp_proxy
ip::tcp::acceptor acceptor_;
ptr_type session_;
unsigned short upstream_port_;
std::string upstream_host_;
string upstream_host_;
};
};
}
void push_regex(char* arg, bool case_sensitive, vector<pair<string,std::regex>> &v){
void push_regex(char* arg, bool case_sensitive, vector<pair<string,regex>> &v){
size_t expr_len = (strlen(arg)-2)/2;
char expr[expr_len];
unhexlify(arg+2, arg+strlen(arg)-1, expr);
string expr_str(expr, expr_len);
try{
if (case_sensitive){
std::regex regex(expr_str);
regex regex(expr_str);
#ifdef DEBUG
cout << "Added case sensitive regex " << expr_str << endl;
#endif
v.push_back(make_pair(string(arg), regex));
} else {
std::regex regex(expr_str,std::regex_constants::icase);
regex regex(expr_str,regex_constants::icase);
#ifdef DEBUG
cout << "Added case insensitive regex " << expr_str << endl;
#endif
v.push_back(make_pair(string(arg), regex));
}
} catch(...){
std::cerr << "Regex " << expr << " was not compiled successfully" << std::endl;
cerr << "Regex " << expr << " was not compiled successfully" << endl;
}
}
@@ -354,7 +350,7 @@ void update_regex(){
fstream fd;
fd.open(config_file,ios::in);
if (!fd.is_open()){
std::cerr << "Error: config file couln't be opened" << std::endl;
cerr << "Error: config file couln't be opened" << endl;
exit(1);
}
@@ -413,14 +409,14 @@ int main(int argc, char* argv[])
{
if (argc < 6)
{
std::cerr << "usage: tcpproxy_server <local host ip> <local port> <forward host ip> <forward port> <config_file>" << std::endl;
cerr << "usage: tcpproxy_server <local host ip> <local port> <forward host ip> <forward port> <config_file>" << endl;
return 1;
}
const unsigned short local_port = static_cast<unsigned short>(::atoi(argv[2]));
const unsigned short forward_port = static_cast<unsigned short>(::atoi(argv[4]));
const std::string local_host = argv[1];
const std::string forward_host = argv[3];
const string local_host = argv[1];
const string forward_host = argv[3];
config_file = argv[5];
@@ -445,9 +441,9 @@ int main(int argc, char* argv[])
ios.run();
}
catch(std::exception& e)
catch(exception& e)
{
std::cerr << "Error: " << e.what() << std::endl;
cerr << "Error: " << e.what() << endl;
return 1;
}

View File

@@ -1,13 +1,13 @@
{
"files": {
"main.css": "/static/css/main.c375ae17.css",
"main.js": "/static/js/main.3ae3ab4b.js",
"main.js": "/static/js/main.76d17c5c.js",
"index.html": "/index.html",
"main.c375ae17.css.map": "/static/css/main.c375ae17.css.map",
"main.3ae3ab4b.js.map": "/static/js/main.3ae3ab4b.js.map"
"main.76d17c5c.js.map": "/static/js/main.76d17c5c.js.map"
},
"entrypoints": [
"static/css/main.c375ae17.css",
"static/js/main.3ae3ab4b.js"
"static/js/main.76d17c5c.js"
]
}

View File

@@ -1 +1 @@
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png"><link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png"><link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png"><link rel="manifest" href="/site.webmanifest"><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#FFFFFFFF"/><meta name="description" content="Firegex by Pwnzer0tt1"/><title>Firegex</title><script defer="defer" src="/static/js/main.3ae3ab4b.js"></script><link href="/static/css/main.c375ae17.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png"><link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png"><link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png"><link rel="manifest" href="/site.webmanifest"><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#FFFFFFFF"/><meta name="description" content="Firegex by Pwnzer0tt1"/><title>Firegex</title><script defer="defer" src="/static/js/main.76d17c5c.js"></script><link href="/static/css/main.c375ae17.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>

File diff suppressed because one or more lines are too long

View File

@@ -2,7 +2,7 @@ import { Button, Group, Space, TextInput, Notification, Switch, NativeSelect, To
import { useForm } from '@mantine/hooks';
import React, { useState } from 'react';
import { RegexAddForm } from '../js/models';
import { addregex, b64encode, fireUpdateRequest, getHumanReadableRegex, okNotify } from '../js/utils';
import { addregex, b64encode, fireUpdateRequest, getBinaryRegex, getHumanReadableRegex, okNotify } from '../js/utils';
import { ImCross } from "react-icons/im"
import FilterTypeSelector from './FilterTypeSelector';
@@ -12,7 +12,6 @@ type RegexAddInfo = {
type:string,
mode:string,
is_case_insensitive:boolean,
regex_exact:boolean,
percentage_encoding:boolean
}
@@ -24,7 +23,6 @@ function AddNewRegex({ opened, onClose, service }:{ opened:boolean, onClose:()=>
type:"blacklist",
mode:"C <-> S",
is_case_insensitive:false,
regex_exact:false,
percentage_encoding:false
},
validationRules:{
@@ -47,12 +45,9 @@ function AddNewRegex({ opened, onClose, service }:{ opened:boolean, onClose:()=>
setSubmitLoading(true)
const filter_mode = ({'C -> S':'C', 'S -> C':'S', 'C <-> S':'B'}[values.mode])
let final_regex = values.regex
let final_regex:string|number[] = values.regex
if (values.percentage_encoding){
final_regex = decodeURIComponent(final_regex)
}
if(!values.regex_exact){
final_regex = ".*"+final_regex+".*"
final_regex = getBinaryRegex(final_regex)
}
const request:RegexAddForm = {
@@ -105,11 +100,6 @@ function AddNewRegex({ opened, onClose, service }:{ opened:boolean, onClose:()=>
{...form.getInputProps('is_case_insensitive', { type: 'checkbox' })}
/>
<Space h="md" />
<Switch
label="Match exactly the regex"
{...form.getInputProps('regex_exact', { type: 'checkbox' })}
/>
<Space h="md" />
<NativeSelect
data={['C -> S', 'S -> C', 'C <-> S']}
label="Choose the source of the packets to filter"

View File

@@ -15,12 +15,6 @@ function RegexView({ regexInfo }:{ regexInfo:RegexFilter }) {
regexInfo.mode === "B"? "S <-> C": "🤔"
let regex_expr = getHumanReadableRegex(regexInfo.regex);
let exact_regex = true;
if (regex_expr.length>=4 && regex_expr.startsWith(".*") && regex_expr.endsWith(".*")){
regex_expr = regex_expr.substring(2,regex_expr.length-2)
exact_regex = false;
}
const [deleteModal, setDeleteModal] = useState(false);
const [tooltipOpened, setTooltipOpened] = useState(false);
@@ -72,9 +66,7 @@ function RegexView({ regexInfo }:{ regexInfo:RegexFilter }) {
<Grid.Col style={{width:"100%"}} span={6}>
<Space h="xs" />
<div className='center-flex-row'>
<Badge size="md" color={exact_regex?"grape":"pink"} variant="filled">Match: {exact_regex?"EXACT":"FIND"}</Badge>
<Space h="xs" />
<Badge size="md" color={regexInfo.is_case_sensitive?"red":"green"} variant="filled">Case: {regexInfo.is_case_sensitive?"SENSIIVE":"INSENSITIVE"}</Badge>
<Badge size="md" color={regexInfo.is_case_sensitive?"grape":"pink"} variant="filled">Case: {regexInfo.is_case_sensitive?"SENSIIVE":"INSENSITIVE"}</Badge>
<Space h="xs" />
<Badge size="md" color="yellow" variant="filled">Packets filtered: {regexInfo.n_packets}</Badge>
<Space h="xs" />

View File

@@ -137,7 +137,36 @@ export function getHumanReadableRegex(regexB64:string){
if (unescapedChars.includes(byte)){
res+=byte
}else{
res+="%"+regex[i].toString(16)
let hex_data = regex[i].toString(16)
if (hex_data.length === 1) hex_data = "0"+hex_data
res+="%"+hex_data
}
}
return res
}
const hexChars = "0123456789abcdefABCDEF"
export function getBinaryRegex(regexPercentageEncoded:string):number[]{
const regex = Buffer.from(regexPercentageEncoded)
let res = []
for (let i=0; i < regex.length; i++){
const byte = String.fromCharCode(regex[i]);
if ("%" === byte){
if(i+2 < regex.length){
const byte_1 = String.fromCharCode(regex[i+1]);
const byte_2 = String.fromCharCode(regex[i+2]);
if(hexChars.includes(byte_1) && hexChars.includes(byte_2)){
res.push(parseInt(byte_1+byte_2,16))
i += 2
}else{
res.push(regex[i])
}
}else{
res.push(regex[i])
}
}else{
res.push(regex[i])
}
}
return res
@@ -163,6 +192,6 @@ export function okNotify(title:string, description:string ){
});
}
export function b64encode(data:string){
export function b64encode(data:number[]|string){
return Buffer.from(data).toString('base64')
}