Skip to content

Commit

Permalink
--fake-gen option: generate random-filled Fake Packets
Browse files Browse the repository at this point in the history
This option is similar to fake-from-hex, but generates number of
packets with random payload.
  • Loading branch information
ValdikSS committed Sep 14, 2024
1 parent f0d4212 commit 15793fb
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ Usage: goodbyedpi.exe [OPTION...]
--fake-from-hex <value> Load fake packets for Fake Request Mode from HEX values (like 1234abcDEF).
This option can be supplied multiple times, in this case each fake packet
would be sent on every request in the command line argument order.
--fake-gen <value> Generate random-filled fake packets for Fake Request Mode, value of them
(up to 30).
--max-payload [value] packets with TCP payload data more than [value] won't be processed.
Use this option to reduce CPU usage by skipping huge amount of data
(like file transfers) in already established sessions.
Expand Down
24 changes: 24 additions & 0 deletions src/fakepackets.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <stdio.h>
#define _CRT_RAND_S
#include <stdlib.h>
#include <stdbool.h>
#include <ctype.h>
Expand Down Expand Up @@ -284,3 +285,26 @@ int fake_load_from_hex(const char *data) {

return fake_add(finaldata, len / 2);
}

int fake_load_random(unsigned int count, unsigned int maxsize) {
if (count < 1 || count > sizeof(fakes) / sizeof(*fakes))
return 1;

unsigned int random = 0;

for (unsigned int i=0; i<count; i++) {
unsigned int len = 0;
if (rand_s(&len))
return 1;
len = 8 + (len % maxsize);

unsigned char *data = calloc(len, 1);
for (unsigned int j=0; j<len; j++) {
rand_s(&random);
data[j] = random % 0xFF;
}
if (fake_add(data, len))
return 2;
}
return 0;
}
8 changes: 8 additions & 0 deletions src/goodbyedpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ static struct option long_options[] = {
{"reverse-frag",no_argument, 0, '(' },
{"max-payload", optional_argument, 0, '|' },
{"fake-from-hex", required_argument, 0, 'u' },
{"fake-gen", required_argument, 0, 'j' },
{"debug-exit", optional_argument, 0, 'x' },
{0, 0, 0, 0 }
};
Expand Down Expand Up @@ -946,6 +947,11 @@ int main(int argc, char *argv[]) {
printf("WARNING: bad fake HEX value %s\n", optarg);
}
break;
case 'j': // --fake-gen
if (fake_load_random(atoub(optarg, "Fake generator parameter error!"))) {
puts("WARNING: fake generator has failed!");
}
break;
case 'x': // --debug-exit
debug_exit = true;
break;
Expand Down Expand Up @@ -997,6 +1003,8 @@ int main(int argc, char *argv[]) {
" --fake-from-hex <value> Load fake packets for Fake Request Mode from HEX values (like 1234abcDEF).\n"
" This option can be supplied multiple times, in this case each fake packet\n"
" would be sent on every request in the command line argument order.\n"
" --fake-gen <value> Generate random-filled fake packets for Fake Request Mode, value of them\n"
" (up to 30).\n"
" --max-payload [value] packets with TCP payload data more than [value] won't be processed.\n"
" Use this option to reduce CPU usage by skipping huge amount of data\n"
" (like file transfers) in already established sessions.\n"
Expand Down

0 comments on commit 15793fb

Please sign in to comment.