@@ -61,8 +61,9 @@ WINSOCK_API_LINKAGE INT WSAAPI inet_pton(INT Family, LPCSTR pStringBuf, PVOID pA
61
61
62
62
/* #IPID# is a template to find&replace */
63
63
#define IPID_TEMPLATE "#IPID#"
64
+ #define MAXPAYLOADSIZE_TEMPLATE "#MAXPAYLOADSIZE#"
64
65
#define FILTER_STRING_TEMPLATE \
65
- "(tcp and !impostor and !loopback and " \
66
+ "(tcp and !impostor and !loopback " MAXPAYLOADSIZE_TEMPLATE " and " \
66
67
"((inbound and (" \
67
68
"(" \
68
69
"(" \
@@ -169,6 +170,7 @@ static struct option long_options[] = {
169
170
{"wrong-seq" , no_argument , 0 , ')' },
170
171
{"native-frag" , no_argument , 0 , '*' },
171
172
{"reverse-frag" ,no_argument , 0 , '(' },
173
+ {"max-payload" , optional_argument , 0 , '|' },
172
174
{0 , 0 , 0 , 0 }
173
175
};
174
176
@@ -178,7 +180,7 @@ static char *filter_passive_string = NULL;
178
180
static void add_filter_str (int proto , int port ) {
179
181
const char * udp = " or (udp and !impostor and !loopback and " \
180
182
"(udp.SrcPort == %d or udp.DstPort == %d))" ;
181
- const char * tcp = " or (tcp and !impostor and !loopback and " \
183
+ const char * tcp = " or (tcp and !impostor and !loopback " MAXPAYLOADSIZE_TEMPLATE " and " \
182
184
"(tcp.SrcPort == %d or tcp.DstPort == %d))" ;
183
185
184
186
char * current_filter = filter_string ;
@@ -212,11 +214,25 @@ static void add_ip_id_str(int id) {
212
214
filter_passive_string = newstr ;
213
215
}
214
216
215
- static void finalize_filter_strings ( ) {
217
+ static void add_maxpayloadsize_str ( unsigned short maxpayload ) {
216
218
char * newstr ;
219
+ const char * maxpayloadsize_str = "and (tcp.PayloadLength ? tcp.PayloadLength < %hu : true)" ;
220
+ char * addfilter = malloc (strlen (maxpayloadsize_str ) + 16 );
221
+
222
+ sprintf (addfilter , maxpayloadsize_str , maxpayload );
223
+
224
+ newstr = repl_str (filter_string , MAXPAYLOADSIZE_TEMPLATE , addfilter );
225
+ free (filter_string );
226
+ filter_string = newstr ;
227
+ }
228
+
229
+ static void finalize_filter_strings () {
230
+ char * newstr , * newstr2 ;
217
231
218
- newstr = repl_str (filter_string , IPID_TEMPLATE , "" );
232
+ newstr2 = repl_str (filter_string , IPID_TEMPLATE , "" );
233
+ newstr = repl_str (newstr2 , MAXPAYLOADSIZE_TEMPLATE , "" );
219
234
free (filter_string );
235
+ free (newstr2 );
220
236
filter_string = newstr ;
221
237
222
238
newstr = repl_str (filter_passive_string , IPID_TEMPLATE , "" );
@@ -558,6 +574,7 @@ int main(int argc, char *argv[]) {
558
574
unsigned int http_fragment_size = 0 ;
559
575
unsigned int https_fragment_size = 0 ;
560
576
unsigned int current_fragment_size = 0 ;
577
+ unsigned short max_payload_size = 0 ;
561
578
BYTE should_send_fake = 0 ;
562
579
BYTE ttl_of_fake_packet = 0 ;
563
580
BYTE ttl_min_nhops = 0 ;
@@ -845,6 +862,14 @@ int main(int argc, char *argv[]) {
845
862
do_fragment_http_persistent = 1 ;
846
863
do_fragment_http_persistent_nowait = 1 ;
847
864
break ;
865
+ case '|' : // --max-payload
866
+ if (!optarg && argv [optind ] && argv [optind ][0 ] != '-' )
867
+ optarg = argv [optind ];
868
+ if (optarg )
869
+ max_payload_size = atousi (optarg , "Max payload size parameter error!" );
870
+ if (!max_payload_size )
871
+ max_payload_size = 1200 ;
872
+ break ;
848
873
default :
849
874
puts ("Usage: goodbyedpi.exe [OPTION...]\n"
850
875
" -p block passive DPI\n"
@@ -888,9 +913,13 @@ int main(int argc, char *argv[]) {
888
913
" --reverse-frag fragment (split) the packets just as --native-frag, but send them in the\n"
889
914
" reversed order. Works with the websites which could not handle segmented\n"
890
915
" HTTPS TLS ClientHello (because they receive the TCP flow \"combined\").\n"
891
- "\n"
892
- "\n"
893
- "LEGACY modesets:\n"
916
+ " --max-payload [value] packets with TCP payload data more than [value] won't be processed.\n"
917
+ " Use this option to reduce CPU usage by skipping huge amount of data\n"
918
+ " (like file transfers) in already established sessions.\n"
919
+ " May skip some huge HTTP requests from being processed.\n"
920
+ " Default (if set): --max-payload 1200.\n"
921
+ "\n" );
922
+ puts ("LEGACY modesets:\n"
894
923
" -1 -p -r -s -f 2 -k 2 -n -e 2 (most compatible mode)\n"
895
924
" -2 -p -r -s -f 2 -k 2 -n -e 40 (better speed for HTTPS yet still compatible)\n"
896
925
" -3 -p -r -s -e 40 (better speed for HTTP and HTTPS)\n"
@@ -935,7 +964,8 @@ int main(int argc, char *argv[]) {
935
964
"Allow missing SNI: %d\n" /* 15 */
936
965
"Fake requests, TTL: %s (fixed: %hu, auto: %hu-%hu-%hu, min distance: %hu)\n" /* 16 */
937
966
"Fake requests, wrong checksum: %d\n" /* 17 */
938
- "Fake requests, wrong SEQ/ACK: %d\n" , /* 18 */
967
+ "Fake requests, wrong SEQ/ACK: %d\n" /* 18 */
968
+ "Max payload size: %hu\n" , /* 19 */
939
969
do_passivedpi , /* 1 */
940
970
(do_fragment_http ? http_fragment_size : 0 ), /* 2 */
941
971
(do_fragment_http_persistent ? http_fragment_size : 0 ),/* 3 */
@@ -955,7 +985,8 @@ int main(int argc, char *argv[]) {
955
985
ttl_of_fake_packet , do_auto_ttl ? auto_ttl_1 : 0 , do_auto_ttl ? auto_ttl_2 : 0 ,
956
986
do_auto_ttl ? auto_ttl_max : 0 , ttl_min_nhops ,
957
987
do_wrong_chksum , /* 17 */
958
- do_wrong_seq /* 18 */
988
+ do_wrong_seq , /* 18 */
989
+ max_payload_size /* 19 */
959
990
);
960
991
961
992
if (do_fragment_http && http_fragment_size > 2 && !do_native_frag ) {
@@ -970,8 +1001,10 @@ int main(int argc, char *argv[]) {
970
1001
exit (EXIT_FAILURE );
971
1002
}
972
1003
973
- puts ("\nOpening filter" );
1004
+ if (max_payload_size )
1005
+ add_maxpayloadsize_str (max_payload_size );
974
1006
finalize_filter_strings ();
1007
+ puts ("\nOpening filter" );
975
1008
filter_num = 0 ;
976
1009
977
1010
if (do_passivedpi ) {
0 commit comments