Skip to content

Commit 5d6c91f

Browse files
author
bol-van
committed
nfqws: add marker support for seqovl pos
1 parent cde3ca1 commit 5d6c91f

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

nfq/desync.c

+13-9
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,7 @@ static uint8_t dpi_desync_tcp_packet_play(bool replay, size_t reasm_offset, uint
840840
uint8_t *p, *phost=NULL;
841841
const uint8_t *rdata_payload = dis->data_payload;
842842
size_t rlen_payload = dis->len_payload;
843-
size_t split_pos;
843+
size_t split_pos, seqovl_pos;
844844
size_t multisplit_pos[MAX_SPLITS];
845845
int multisplit_count;
846846
int i;
@@ -1165,6 +1165,7 @@ static uint8_t dpi_desync_tcp_packet_play(bool replay, size_t reasm_offset, uint
11651165
DLOG("all multisplit pos are outside of this packet\n");
11661166
}
11671167
}
1168+
seqovl_pos = ResolvePos(rdata_payload, rlen_payload, l7proto, &dp->seqovl);
11681169
}
11691170
else if (dp->desync_mode==DESYNC_FAKEDSPLIT || dp->desync_mode==DESYNC_FAKEDDISORDER || dp->desync_mode2==DESYNC_FAKEDSPLIT || dp->desync_mode2==DESYNC_FAKEDDISORDER)
11701171
{
@@ -1186,12 +1187,15 @@ static uint8_t dpi_desync_tcp_packet_play(bool replay, size_t reasm_offset, uint
11861187
DLOG("normalized regular split pos : %zu\n",split_pos);
11871188
else
11881189
DLOG("regular split pos is outside of this packet\n");
1190+
seqovl_pos = ResolvePos(rdata_payload, rlen_payload, l7proto, &dp->seqovl);
11891191
}
11901192
else
11911193
{
11921194
multisplit_count=0;
1193-
split_pos = 0;
1195+
split_pos = seqovl_pos = 0;
11941196
}
1197+
seqovl_pos = pos_normalize(seqovl_pos,reasm_offset,dis->len_payload);
1198+
if (seqovl_pos) DLOG("normalized seqovl pos : %zu\n",seqovl_pos);
11951199

11961200
// we do not need reasm buffer anymore
11971201
reasm_orig_cancel(ctrack);
@@ -1283,7 +1287,7 @@ static uint8_t dpi_desync_tcp_packet_play(bool replay, size_t reasm_offset, uint
12831287
// do seqovl only to the first packet
12841288
// otherwise it's prone to race condition on server side
12851289
// what happens first : server pushes socket buffer to process or another packet with seqovl arrives
1286-
seqovl = i==0 ? dp->desync_seqovl : 0;
1290+
seqovl = i==0 ? seqovl_pos : 0;
12871291
#ifdef __linux__
12881292
// only linux return error if MTU is exceeded
12891293
for(;;seqovl=0)
@@ -1356,11 +1360,11 @@ static uint8_t dpi_desync_tcp_packet_play(bool replay, size_t reasm_offset, uint
13561360
// real observations revealed that server can receive overlap junk instead of real data
13571361
if (i==0)
13581362
{
1359-
if (dp->desync_seqovl>=from)
1363+
if (seqovl_pos>=from)
13601364
DLOG("seqovl>=split_pos (%u>=%zu). cancelling seqovl for part %d.\n",seqovl,from,i+2);
13611365
else
13621366
{
1363-
seqovl = dp->desync_seqovl;
1367+
seqovl = seqovl_pos;
13641368
seg_len = to-from+seqovl;
13651369
if (seg_len>sizeof(ovlseg))
13661370
{
@@ -1397,13 +1401,13 @@ static uint8_t dpi_desync_tcp_packet_play(bool replay, size_t reasm_offset, uint
13971401
size_t seg_len;
13981402
unsigned int seqovl;
13991403

1400-
if (dp->desync_seqovl>=split_pos)
1404+
if (seqovl_pos>=split_pos)
14011405
{
1402-
DLOG("seqovl>=split_pos (%u>=%zu). cancelling seqovl.\n",dp->desync_seqovl,split_pos);
1406+
DLOG("seqovl>=split_pos (%u>=%zu). cancelling seqovl.\n",seqovl_pos,split_pos);
14031407
seqovl = 0;
14041408
}
14051409
else
1406-
seqovl = dp->desync_seqovl;
1410+
seqovl = seqovl_pos;
14071411

14081412
if (split_pos<dis->len_payload)
14091413
{
@@ -1484,7 +1488,7 @@ static uint8_t dpi_desync_tcp_packet_play(bool replay, size_t reasm_offset, uint
14841488
if (!rawsend_rep(dp->desync_repeats,(struct sockaddr *)&dst, desync_fwmark, ifout , fakeseg, fakeseg_len))
14851489
return verdict;
14861490

1487-
unsigned int seqovl = dp->desync_seqovl;
1491+
unsigned int seqovl = seqovl_pos;
14881492
#ifdef __linux__
14891493
// only linux return error if MTU is exceeded
14901494
for(;;seqovl=0)

nfq/nfqws.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -855,6 +855,7 @@ static void SplitDebug(void)
855855
dp = &dpl->dp;
856856
for(int x=0;x<dp->split_count;x++)
857857
DLOG("profile %d multisplit %s %d\n",dp->n,posmarker_name(dp->splits[x].marker),dp->splits[x].pos);
858+
if (!PROTO_POS_EMPTY(&dp->seqovl)) DLOG("profile %d seqovl %s %d\n",dp->n,posmarker_name(dp->seqovl.marker),dp->seqovl.pos);
858859
}
859860
}
860861

@@ -1055,7 +1056,7 @@ static void exithelp(void)
10551056
"\t\t\t\t\t\t; markers: method,host,endhost,sld,endsld,midsld,sniext\n"
10561057
"\t\t\t\t\t\t; full list is only used by multisplit and multidisorder\n"
10571058
"\t\t\t\t\t\t; fakedsplit/fakeddisorder use first l7-protocol-compatible parameter if present, first abs value otherwise\n"
1058-
" --dpi-desync-split-seqovl=<int>\t\t; use sequence overlap before first sent original split segment\n"
1059+
" --dpi-desync-split-seqovl=N|-N|marker+N|marker-N ; use sequence overlap before first sent original split segment\n"
10591060
" --dpi-desync-split-seqovl-pattern=<filename>|0xHEX ; pattern for the fake part of overlap\n"
10601061
" --dpi-desync-ipfrag-pos-tcp=<8..%u>\t\t; ip frag position starting from the transport header. multiple of 8, default %u.\n"
10611062
" --dpi-desync-ipfrag-pos-udp=<8..%u>\t\t; ip frag position starting from the transport header. multiple of 8, default %u.\n"
@@ -1589,9 +1590,9 @@ int main(int argc, char **argv)
15891590
dp->split_count++;
15901591
break;
15911592
case 26: /* dpi-desync-split-seqovl */
1592-
if (sscanf(optarg,"%u",&dp->desync_seqovl)<1)
1593+
if (!parse_split_pos(optarg, &dp->seqovl))
15931594
{
1594-
DLOG_ERR("dpi-desync-split-seqovl is not valid\n");
1595+
DLOG_ERR("Invalid argument for dpi-desync-split-seqovl\n");
15951596
exit_clean(1);
15961597
}
15971598
break;

nfq/params.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,12 @@ struct desync_profile
5555
char hostspell[4];
5656
enum dpi_desync_mode desync_mode0,desync_mode,desync_mode2;
5757
bool desync_retrans,desync_skip_nosni,desync_any_proto;
58-
unsigned int desync_repeats,desync_seqovl,desync_ipfrag_pos_tcp,desync_ipfrag_pos_udp;
58+
unsigned int desync_repeats,desync_ipfrag_pos_tcp,desync_ipfrag_pos_udp;
5959

6060
// multisplit
6161
struct proto_pos splits[MAX_SPLITS];
6262
int split_count;
63+
struct proto_pos seqovl;
6364

6465
char desync_start_mode, desync_cutoff_mode; // n - packets, d - data packets, s - relative sequence
6566
unsigned int desync_start, desync_cutoff;

0 commit comments

Comments
 (0)