-
Notifications
You must be signed in to change notification settings - Fork 3
/
rand_seq.c
123 lines (107 loc) · 2.87 KB
/
rand_seq.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/* Very simple tool to generate randomized sequence numbers for testing
* purposes.
* License: GPLv3, see `LICENSE' file.
* (C) 2019 Steffen Wendzel, www.wendzel.de
*
* This script can be used as a parameter for the CCEAP client.
*/
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <assert.h>
#include <time.h>
int two_array[2][2] = {
{ 0, 1 },
{ 1, 0 }
};
int three_array[6][3] = {
{ 0, 1, 2 },
{ 0, 2, 1 },
{ 1, 0, 2 },
{ 1, 2, 0 },
{ 2, 0, 1 },
{ 2, 1, 0 }
};
int four_array[24][4] = {
{ 0, 1, 2, 3 },
{ 0, 1, 3, 2 },
{ 0, 2, 1, 3 },
{ 0, 2, 3, 1 },
{ 0, 3, 1, 2 },
{ 0, 3, 2, 1 },
{ 1, 0, 2, 3 },
{ 1, 0, 3, 2 },
{ 1, 2, 0, 3 },
{ 1, 2, 3, 0 },
{ 1, 3, 0, 2 },
{ 1, 3, 2, 0 },
{ 2, 0, 1, 3 },
{ 2, 0, 3, 1 },
{ 2, 1, 0, 3 },
{ 2, 1, 3, 0 },
{ 2, 3, 0, 1 },
{ 2, 3, 1, 0 },
{ 3, 0, 1, 2 },
{ 3, 0, 2, 1 },
{ 3, 1, 0, 2 },
{ 3, 1, 2, 0 },
{ 3, 2, 0, 1 },
{ 3, 2, 1, 0 },
};
#define PRINT_COMMA putchar(',');
int main(int argc, char *argv[])
{
int cur_seq = 0;
int num_pairs_to_gen = 2; /* how many seq. pairs should be generated? */
int max_seq_val = 256; /* A header field has a max. value it can contain,
* in CCEAP it is 8 bits for the sequence no. field. */
int num_symbols = 2; /* A covert channel needs at least 2 symbols. */
int first = 1;
int counter = 0;
extern char *__progname;
if (argc <= 3) {
fprintf(stderr, "usage: %s [#pairs to generate] [max_seq_val] [symbols (2||3||4)]\n", __progname);
fprintf(stderr, "Please note that you can use the tool in combination with CCEAP\n"
"the following way: ./client -D ... -P ... -s `./%s [parameters]`\n", __progname);
exit(1);
}
num_pairs_to_gen = atoi(argv[1]);
assert(num_pairs_to_gen > 1);
max_seq_val = atoi(argv[2]);
assert(max_seq_val > 1);
num_symbols = atoi(argv[3]);
assert(num_symbols >=2 && num_symbols <=4);
srand(time(NULL));
for (counter = 0; counter < num_pairs_to_gen; counter++) {
if (first)
first = 0;
else
PRINT_COMMA /* comma behind every new pair */
int rand_val = rand();
if (num_symbols == 2) {
rand_val %= 2;
printf("%i,%i",
(cur_seq + two_array[rand_val][0]) % max_seq_val,
(cur_seq + two_array[rand_val][1]) % max_seq_val);
cur_seq += 2;
} else if (num_symbols == 3) {
rand_val %= 6;
printf("%i,%i,%i",
(cur_seq + three_array[rand_val][0]) % max_seq_val,
(cur_seq + three_array[rand_val][1]) % max_seq_val,
(cur_seq + three_array[rand_val][2]) % max_seq_val);
cur_seq += 3;
} else if (num_symbols == 4) {
rand_val %= 24;
printf("%i,%i,%i,%i",
(cur_seq + four_array[rand_val][0]) % max_seq_val,
(cur_seq + four_array[rand_val][1]) % max_seq_val,
(cur_seq + four_array[rand_val][2]) % max_seq_val,
(cur_seq + four_array[rand_val][3]) % max_seq_val);
cur_seq += 4;
} else {
perror("internal error.\n"); exit(99);
}
}
return 0;
}