mirror of
https://github.com/bol-van/zapret.git
synced 2024-12-27 11:50:34 +05:00
nfqws: move code
This commit is contained in:
parent
a17e490851
commit
284f911785
@ -12,29 +12,6 @@ static void ut_oom_recover(void *elem)
|
|||||||
oom = true;
|
oom = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *l7proto_str(t_l7proto l7)
|
|
||||||
{
|
|
||||||
switch(l7)
|
|
||||||
{
|
|
||||||
case HTTP: return "http";
|
|
||||||
case TLS: return "tls";
|
|
||||||
case QUIC: return "quic";
|
|
||||||
case WIREGUARD: return "wireguard";
|
|
||||||
case DHT: return "dht";
|
|
||||||
default: return "unknown";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
bool l7_proto_match(t_l7proto l7proto, uint32_t filter_l7)
|
|
||||||
{
|
|
||||||
return (l7proto==UNKNOWN && (filter_l7 & L7_PROTO_UNKNOWN)) ||
|
|
||||||
(l7proto==HTTP && (filter_l7 & L7_PROTO_HTTP)) ||
|
|
||||||
(l7proto==TLS && (filter_l7 & L7_PROTO_TLS)) ||
|
|
||||||
(l7proto==QUIC && (filter_l7 & L7_PROTO_QUIC)) ||
|
|
||||||
(l7proto==WIREGUARD && (filter_l7 & L7_PROTO_WIREGUARD)) ||
|
|
||||||
(l7proto==DHT && (filter_l7 & L7_PROTO_DHT));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static const char *connstate_s[]={"SYN","ESTABLISHED","FIN"};
|
static const char *connstate_s[]={"SYN","ESTABLISHED","FIN"};
|
||||||
|
|
||||||
static void connswap(const t_conn *c, t_conn *c2)
|
static void connswap(const t_conn *c, t_conn *c2)
|
||||||
|
@ -4,8 +4,6 @@
|
|||||||
// this conntrack is not bullet-proof
|
// this conntrack is not bullet-proof
|
||||||
// its designed to satisfy dpi desync needs only
|
// its designed to satisfy dpi desync needs only
|
||||||
|
|
||||||
#include "packet_queue.h"
|
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
@ -19,6 +17,8 @@
|
|||||||
#include <netinet/tcp.h>
|
#include <netinet/tcp.h>
|
||||||
#include <netinet/udp.h>
|
#include <netinet/udp.h>
|
||||||
|
|
||||||
|
#include "packet_queue.h"
|
||||||
|
#include "protocol.h"
|
||||||
|
|
||||||
//#define HASH_BLOOM 20
|
//#define HASH_BLOOM 20
|
||||||
#define HASH_NONFATAL_OOM 1
|
#define HASH_NONFATAL_OOM 1
|
||||||
@ -53,16 +53,6 @@ typedef struct {
|
|||||||
// FIN - FIN or RST received
|
// FIN - FIN or RST received
|
||||||
typedef enum {SYN=0, ESTABLISHED, FIN} t_connstate;
|
typedef enum {SYN=0, ESTABLISHED, FIN} t_connstate;
|
||||||
|
|
||||||
typedef enum {UNKNOWN=0, HTTP, TLS, QUIC, WIREGUARD, DHT} t_l7proto;
|
|
||||||
#define L7_PROTO_HTTP 0x00000001
|
|
||||||
#define L7_PROTO_TLS 0x00000002
|
|
||||||
#define L7_PROTO_QUIC 0x00000004
|
|
||||||
#define L7_PROTO_WIREGUARD 0x00000008
|
|
||||||
#define L7_PROTO_DHT 0x00000010
|
|
||||||
#define L7_PROTO_UNKNOWN 0x80000000
|
|
||||||
const char *l7proto_str(t_l7proto l7);
|
|
||||||
bool l7_proto_match(t_l7proto l7proto, uint32_t filter_l7);
|
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
bool bCheckDone, bCheckResult, bCheckExcluded; // hostlist check result cache
|
bool bCheckDone, bCheckResult, bCheckExcluded; // hostlist check result cache
|
||||||
|
29
nfq/desync.c
29
nfq/desync.c
@ -607,31 +607,6 @@ static void autottl_discover(t_ctrack *ctrack, bool bIpv6)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t resolve_split(const uint8_t *data, size_t sz, t_l7proto l7proto, const struct split_pos *sp)
|
|
||||||
{
|
|
||||||
switch(l7proto)
|
|
||||||
{
|
|
||||||
case HTTP:
|
|
||||||
return HttpPos(sp->marker, sp->pos, data, sz);
|
|
||||||
case TLS:
|
|
||||||
return TLSPos(sp->marker, sp->pos, data, sz);
|
|
||||||
default:
|
|
||||||
return AnyProtoPos(sp->marker, sp->pos, data, sz);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
static void resolve_multisplit(const uint8_t *data, size_t sz, t_l7proto l7proto, const struct desync_profile *dp, size_t *pos, int *pos_count)
|
|
||||||
{
|
|
||||||
int i,j;
|
|
||||||
for(i=j=0;i<dp->split_count;i++)
|
|
||||||
{
|
|
||||||
pos[j] = resolve_split(data,sz,l7proto,dp->splits+i);
|
|
||||||
if (pos[j]) j++;
|
|
||||||
}
|
|
||||||
qsort_size_t(pos, j);
|
|
||||||
j=unique_size_t(pos, j);
|
|
||||||
*pos_count=j;
|
|
||||||
}
|
|
||||||
|
|
||||||
static uint8_t dpi_desync_tcp_packet_play(bool replay, size_t reasm_offset, uint32_t fwmark, const char *ifout, struct dissect *dis)
|
static uint8_t dpi_desync_tcp_packet_play(bool replay, size_t reasm_offset, uint32_t fwmark, const char *ifout, struct dissect *dis)
|
||||||
{
|
{
|
||||||
uint8_t verdict=VERDICT_PASS;
|
uint8_t verdict=VERDICT_PASS;
|
||||||
@ -1157,7 +1132,7 @@ static uint8_t dpi_desync_tcp_packet_play(bool replay, size_t reasm_offset, uint
|
|||||||
if (dp->desync_mode==DESYNC_MULTISPLIT || dp->desync_mode==DESYNC_MULTIDISORDER || dp->desync_mode2==DESYNC_MULTISPLIT || dp->desync_mode2==DESYNC_MULTIDISORDER)
|
if (dp->desync_mode==DESYNC_MULTISPLIT || dp->desync_mode==DESYNC_MULTIDISORDER || dp->desync_mode2==DESYNC_MULTISPLIT || dp->desync_mode2==DESYNC_MULTIDISORDER)
|
||||||
{
|
{
|
||||||
split_pos=0;
|
split_pos=0;
|
||||||
resolve_multisplit(rdata_payload, rlen_payload, l7proto, dp, multisplit_pos, &multisplit_count);
|
ResolveMultiPos(rdata_payload, rlen_payload, l7proto, dp->splits, dp->split_count, multisplit_pos, &multisplit_count);
|
||||||
if (params.debug)
|
if (params.debug)
|
||||||
{
|
{
|
||||||
if (multisplit_count)
|
if (multisplit_count)
|
||||||
@ -1174,7 +1149,7 @@ static uint8_t dpi_desync_tcp_packet_play(bool replay, size_t reasm_offset, uint
|
|||||||
dp->desync_mode2==DESYNC_SPLIT || dp->desync_mode2==DESYNC_SPLIT2 || dp->desync_mode2==DESYNC_DISORDER || dp->desync_mode2==DESYNC_DISORDER2)
|
dp->desync_mode2==DESYNC_SPLIT || dp->desync_mode2==DESYNC_SPLIT2 || dp->desync_mode2==DESYNC_DISORDER || dp->desync_mode2==DESYNC_DISORDER2)
|
||||||
{
|
{
|
||||||
multisplit_count=0;
|
multisplit_count=0;
|
||||||
split_pos = resolve_split(rdata_payload, rlen_payload, l7proto, spos);
|
split_pos = ResolvePos(rdata_payload, rlen_payload, l7proto, spos);
|
||||||
DLOG("regular split pos: %zu\n",split_pos);
|
DLOG("regular split pos: %zu\n",split_pos);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -2048,6 +2048,13 @@ int main(int argc, char **argv)
|
|||||||
LIST_FOREACH(dpl, ¶ms.desync_profiles, next)
|
LIST_FOREACH(dpl, ¶ms.desync_profiles, next)
|
||||||
{
|
{
|
||||||
dp = &dpl->dp;
|
dp = &dpl->dp;
|
||||||
|
|
||||||
|
if (!dp->split_count && (dp->desync_mode==DESYNC_MULTISPLIT || dp->desync_mode==DESYNC_MULTIDISORDER || dp->desync_mode2==DESYNC_MULTISPLIT || dp->desync_mode2==DESYNC_MULTIDISORDER))
|
||||||
|
{
|
||||||
|
DLOG_ERR("multisplit requires explicit split pos\n");
|
||||||
|
exit_clean(1);
|
||||||
|
}
|
||||||
|
|
||||||
// not specified - use desync_ttl value instead
|
// not specified - use desync_ttl value instead
|
||||||
if (dp->desync_ttl6 == 0xFF) dp->desync_ttl6=dp->desync_ttl;
|
if (dp->desync_ttl6 == 0xFF) dp->desync_ttl6=dp->desync_ttl;
|
||||||
if (!AUTOTTL_ENABLED(dp->desync_autottl6)) dp->desync_autottl6 = dp->desync_autottl;
|
if (!AUTOTTL_ENABLED(dp->desync_autottl6)) dp->desync_autottl6 = dp->desync_autottl;
|
||||||
|
10
nfq/params.h
10
nfq/params.h
@ -38,16 +38,10 @@
|
|||||||
#define HOSTLIST_AUTO_FAIL_TIME_DEFAULT 60
|
#define HOSTLIST_AUTO_FAIL_TIME_DEFAULT 60
|
||||||
#define HOSTLIST_AUTO_RETRANS_THRESHOLD_DEFAULT 3
|
#define HOSTLIST_AUTO_RETRANS_THRESHOLD_DEFAULT 3
|
||||||
|
|
||||||
enum log_target { LOG_TARGET_CONSOLE=0, LOG_TARGET_FILE, LOG_TARGET_SYSLOG };
|
|
||||||
|
|
||||||
struct split_pos
|
|
||||||
{
|
|
||||||
int16_t pos;
|
|
||||||
uint8_t marker;
|
|
||||||
};
|
|
||||||
#define SPLIT_POS_EMPTY(sp) ((sp)->marker==PM_ABS && (sp)->pos==0)
|
|
||||||
#define MAX_SPLITS 64
|
#define MAX_SPLITS 64
|
||||||
|
|
||||||
|
enum log_target { LOG_TARGET_CONSOLE=0, LOG_TARGET_FILE, LOG_TARGET_SYSLOG };
|
||||||
|
|
||||||
struct desync_profile
|
struct desync_profile
|
||||||
{
|
{
|
||||||
int n; // number of the profile
|
int n; // number of the profile
|
||||||
|
@ -24,6 +24,27 @@ static bool FindNLD(const uint8_t *dom, size_t dlen, int level, const uint8_t **
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *l7proto_str(t_l7proto l7)
|
||||||
|
{
|
||||||
|
switch(l7)
|
||||||
|
{
|
||||||
|
case HTTP: return "http";
|
||||||
|
case TLS: return "tls";
|
||||||
|
case QUIC: return "quic";
|
||||||
|
case WIREGUARD: return "wireguard";
|
||||||
|
case DHT: return "dht";
|
||||||
|
default: return "unknown";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bool l7_proto_match(t_l7proto l7proto, uint32_t filter_l7)
|
||||||
|
{
|
||||||
|
return (l7proto==UNKNOWN && (filter_l7 & L7_PROTO_UNKNOWN)) ||
|
||||||
|
(l7proto==HTTP && (filter_l7 & L7_PROTO_HTTP)) ||
|
||||||
|
(l7proto==TLS && (filter_l7 & L7_PROTO_TLS)) ||
|
||||||
|
(l7proto==QUIC && (filter_l7 & L7_PROTO_QUIC)) ||
|
||||||
|
(l7proto==WIREGUARD && (filter_l7 & L7_PROTO_WIREGUARD)) ||
|
||||||
|
(l7proto==DHT && (filter_l7 & L7_PROTO_DHT));
|
||||||
|
}
|
||||||
|
|
||||||
#define PM_ABS 0
|
#define PM_ABS 0
|
||||||
#define PM_HOST 1
|
#define PM_HOST 1
|
||||||
@ -104,6 +125,30 @@ static size_t HostPos(uint8_t posmarker, int16_t pos, const uint8_t *data, size_
|
|||||||
}
|
}
|
||||||
return CheckPos(sz,offset);
|
return CheckPos(sz,offset);
|
||||||
}
|
}
|
||||||
|
size_t ResolvePos(const uint8_t *data, size_t sz, t_l7proto l7proto, const struct split_pos *sp)
|
||||||
|
{
|
||||||
|
switch(l7proto)
|
||||||
|
{
|
||||||
|
case HTTP:
|
||||||
|
return HttpPos(sp->marker, sp->pos, data, sz);
|
||||||
|
case TLS:
|
||||||
|
return TLSPos(sp->marker, sp->pos, data, sz);
|
||||||
|
default:
|
||||||
|
return AnyProtoPos(sp->marker, sp->pos, data, sz);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void ResolveMultiPos(const uint8_t *data, size_t sz, t_l7proto l7proto, const struct split_pos *splits, int split_count, size_t *pos, int *pos_count)
|
||||||
|
{
|
||||||
|
int i,j;
|
||||||
|
for(i=j=0;i<split_count;i++)
|
||||||
|
{
|
||||||
|
pos[j] = ResolvePos(data,sz,l7proto,splits+i);
|
||||||
|
if (pos[j]) j++;
|
||||||
|
}
|
||||||
|
qsort_size_t(pos, j);
|
||||||
|
j=unique_size_t(pos, j);
|
||||||
|
*pos_count=j;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
const char *http_methods[] = { "GET /","POST /","HEAD /","OPTIONS /","PUT /","DELETE /","CONNECT /","TRACE /",NULL };
|
const char *http_methods[] = { "GET /","POST /","HEAD /","OPTIONS /","PUT /","DELETE /","CONNECT /","TRACE /",NULL };
|
||||||
|
@ -7,6 +7,16 @@
|
|||||||
#include "crypto/aes-gcm.h"
|
#include "crypto/aes-gcm.h"
|
||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
|
|
||||||
|
typedef enum {UNKNOWN=0, HTTP, TLS, QUIC, WIREGUARD, DHT} t_l7proto;
|
||||||
|
#define L7_PROTO_HTTP 0x00000001
|
||||||
|
#define L7_PROTO_TLS 0x00000002
|
||||||
|
#define L7_PROTO_QUIC 0x00000004
|
||||||
|
#define L7_PROTO_WIREGUARD 0x00000008
|
||||||
|
#define L7_PROTO_DHT 0x00000010
|
||||||
|
#define L7_PROTO_UNKNOWN 0x80000000
|
||||||
|
const char *l7proto_str(t_l7proto l7);
|
||||||
|
bool l7_proto_match(t_l7proto l7proto, uint32_t filter_l7);
|
||||||
|
|
||||||
// pos markers
|
// pos markers
|
||||||
#define PM_ABS 0
|
#define PM_ABS 0
|
||||||
#define PM_HOST 1
|
#define PM_HOST 1
|
||||||
@ -16,11 +26,19 @@
|
|||||||
#define PM_HOST_ENDSLD 5
|
#define PM_HOST_ENDSLD 5
|
||||||
#define PM_HTTP_METHOD 6
|
#define PM_HTTP_METHOD 6
|
||||||
#define PM_SNI_EXT 7
|
#define PM_SNI_EXT 7
|
||||||
|
struct split_pos
|
||||||
|
{
|
||||||
|
int16_t pos;
|
||||||
|
uint8_t marker;
|
||||||
|
};
|
||||||
|
#define SPLIT_POS_EMPTY(sp) ((sp)->marker==PM_ABS && (sp)->pos==0)
|
||||||
bool IsHostMarker(uint8_t posmarker);
|
bool IsHostMarker(uint8_t posmarker);
|
||||||
const char *posmarker_name(uint8_t posmarker);
|
const char *posmarker_name(uint8_t posmarker);
|
||||||
size_t AnyProtoPos(uint8_t posmarker, int16_t pos, const uint8_t *data, size_t sz);
|
size_t AnyProtoPos(uint8_t posmarker, int16_t pos, const uint8_t *data, size_t sz);
|
||||||
size_t HttpPos(uint8_t posmarker, int16_t pos, const uint8_t *data, size_t sz);
|
size_t HttpPos(uint8_t posmarker, int16_t pos, const uint8_t *data, size_t sz);
|
||||||
size_t TLSPos(uint8_t posmarker, int16_t pos, const uint8_t *data, size_t sz);
|
size_t TLSPos(uint8_t posmarker, int16_t pos, const uint8_t *data, size_t sz);
|
||||||
|
size_t ResolvePos(const uint8_t *data, size_t sz, t_l7proto l7proto, const struct split_pos *sp);
|
||||||
|
void ResolveMultiPos(const uint8_t *data, size_t sz, t_l7proto l7proto, const struct split_pos *splits, int split_count, size_t *pos, int *pos_count);
|
||||||
|
|
||||||
extern const char *http_methods[9];
|
extern const char *http_methods[9];
|
||||||
const char *HttpMethod(const uint8_t *data, size_t len);
|
const char *HttpMethod(const uint8_t *data, size_t len);
|
||||||
|
Loading…
Reference in New Issue
Block a user