2024-08-10 18:44:04 +00:00
|
|
|
#include "config.h"
|
2024-12-08 13:06:50 +00:00
|
|
|
#include "types.h"
|
|
|
|
|
2024-09-26 15:11:05 +00:00
|
|
|
#include "types.h"
|
2024-10-12 09:19:33 +00:00
|
|
|
#include "args.h"
|
2024-11-26 16:58:55 +00:00
|
|
|
#include "logging.h"
|
2024-12-08 13:06:50 +00:00
|
|
|
#include "getopt.h"
|
|
|
|
#include "raw_replacements.h"
|
2024-08-10 18:44:04 +00:00
|
|
|
|
2024-12-08 13:06:50 +00:00
|
|
|
#ifdef KERNEL_SPACE
|
|
|
|
static int errno = 0;
|
|
|
|
#define strtol kstrtol
|
|
|
|
#endif
|
2024-08-10 18:44:04 +00:00
|
|
|
|
2024-12-08 13:06:50 +00:00
|
|
|
struct config_t config = default_config_set;
|
2024-10-13 20:31:26 +00:00
|
|
|
|
2024-12-08 13:06:50 +00:00
|
|
|
static int parse_sni_domains(struct domains_list **dlist, const char *domains_str, size_t domains_strlen) {
|
|
|
|
// Empty and shouldn't be used
|
|
|
|
struct domains_list ndomain = {0};
|
|
|
|
struct domains_list *cdomain = &ndomain;
|
2024-10-13 20:31:26 +00:00
|
|
|
|
2024-12-08 13:06:50 +00:00
|
|
|
unsigned int j = 0;
|
|
|
|
for (unsigned int i = 0; i <= domains_strlen; i++) {
|
|
|
|
if (( i == domains_strlen ||
|
|
|
|
domains_str[i] == '\0' ||
|
|
|
|
domains_str[i] == ',' ||
|
|
|
|
domains_str[i] == '\n' )) {
|
2024-10-26 13:18:13 +00:00
|
|
|
|
2024-12-08 13:06:50 +00:00
|
|
|
if (i == j) {
|
|
|
|
j++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int domain_len = (i - j);
|
|
|
|
const char *domain_startp = domains_str + j;
|
|
|
|
struct domains_list *edomain = malloc(sizeof(struct domains_list));
|
|
|
|
*edomain = (struct domains_list){0};
|
|
|
|
if (edomain == NULL) {
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
edomain->domain_len = domain_len;
|
|
|
|
edomain->domain_name = malloc(domain_len + 1);
|
|
|
|
if (edomain->domain_name == NULL) {
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
strncpy(edomain->domain_name, domain_startp, domain_len);
|
|
|
|
edomain->domain_name[domain_len] = '\0';
|
|
|
|
cdomain->next = edomain;
|
|
|
|
cdomain = edomain;
|
|
|
|
|
|
|
|
j = i + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*dlist = ndomain.next;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void free_sni_domains(struct domains_list *dlist) {
|
|
|
|
for (struct domains_list *ldl = dlist; ldl != NULL;) {
|
|
|
|
struct domains_list *ndl = ldl->next;
|
|
|
|
printf("freeing domains\n");
|
|
|
|
SFREE(ldl->domain_name);
|
|
|
|
SFREE(ldl);
|
|
|
|
ldl = ndl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static long parse_numeric_option(const char* value) {
|
|
|
|
errno = 0;
|
|
|
|
|
|
|
|
if (*value == '\0') {
|
|
|
|
errno = EINVAL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
long result;
|
|
|
|
int len;
|
|
|
|
sscanf(value, "%ld%n", &result, &len);
|
|
|
|
if (*(value + len) != '\0') {
|
|
|
|
errno = EINVAL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int parse_udp_dport_range(char *str, struct udp_dport_range **udpr, int *udpr_len) {
|
|
|
|
int seclen = 1;
|
|
|
|
const char *p = str;
|
|
|
|
while (*p != '\0') {
|
|
|
|
if (*p == ',')
|
|
|
|
seclen++;
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef KERNEL_SPACE
|
|
|
|
struct udp_dport_range *udp_dport_ranges = kmalloc(
|
|
|
|
seclen * sizeof(struct udp_dport_range), GFP_KERNEL);
|
|
|
|
|
|
|
|
#else
|
|
|
|
struct udp_dport_range *udp_dport_ranges = malloc(
|
|
|
|
seclen * sizeof(struct udp_dport_range));
|
|
|
|
#endif
|
|
|
|
if (udp_dport_ranges == NULL) {
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
|
|
|
|
p = str;
|
|
|
|
const char *ep = p;
|
|
|
|
while (1) {
|
|
|
|
if (*ep == '\0' || *ep == ',') {
|
|
|
|
if (ep == p) {
|
|
|
|
if (*ep == '\0')
|
|
|
|
break;
|
|
|
|
|
|
|
|
p++, ep++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *endp;
|
|
|
|
long num1;
|
|
|
|
int len;
|
|
|
|
sscanf(p, "%ld%n", &num1, &len);
|
|
|
|
endp = p + len;
|
|
|
|
long num2 = num1;
|
|
|
|
|
|
|
|
if (endp != ep) {
|
|
|
|
if (*endp == '-') {
|
|
|
|
endp++;
|
|
|
|
int len;
|
|
|
|
sscanf(endp, "%ld%n", &num2, &len);
|
|
|
|
endp = endp + len;
|
|
|
|
|
|
|
|
if (endp != ep)
|
|
|
|
goto erret;
|
|
|
|
} else {
|
|
|
|
goto erret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
|
|
|
!(num1 > 0 && num1 < (1 << 16)) ||
|
|
|
|
!(num2 > 0 && num2 < (1 << 16)) ||
|
|
|
|
num2 < num1
|
|
|
|
)
|
|
|
|
goto erret;
|
|
|
|
|
|
|
|
udp_dport_ranges[i] = (struct udp_dport_range){
|
|
|
|
.start = num1,
|
|
|
|
.end = num2
|
|
|
|
};
|
|
|
|
i++;
|
|
|
|
|
|
|
|
if (*ep == '\0') {
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
p = ep + 1;
|
|
|
|
ep = p;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ep++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i == 0) {
|
|
|
|
free(udp_dport_ranges);
|
|
|
|
}
|
|
|
|
|
|
|
|
*udpr = udp_dport_ranges;
|
|
|
|
*udpr_len = i;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
erret:
|
|
|
|
free(udp_dport_ranges);
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Allocates and fills custom fake buffer
|
|
|
|
static int parse_fake_custom_payload(
|
|
|
|
const char *custom_hex_fake,
|
|
|
|
char **custom_fake_buf, unsigned int *custom_fake_len) {
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
size_t custom_hlen = strlen(custom_hex_fake);
|
|
|
|
if ((custom_hlen & 1) == 1) {
|
|
|
|
printf("Custom fake hex should be divisible by two\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t custom_len = custom_hlen >> 1;
|
|
|
|
if (custom_len > MAX_FAKE_SIZE) {
|
|
|
|
printf("Custom fake is too large\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
unsigned char *custom_buf = malloc(custom_len);
|
|
|
|
|
|
|
|
for (int i = 0; i < custom_len; i++) {
|
|
|
|
ret = sscanf(custom_hex_fake + (i << 1), "%2hhx", custom_buf + i);
|
|
|
|
if (ret != 1) {
|
|
|
|
free(custom_buf);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*custom_fake_buf = (char *)custom_buf;
|
|
|
|
*custom_fake_len = custom_len;
|
|
|
|
return 0;
|
|
|
|
}
|
2024-08-10 18:44:04 +00:00
|
|
|
|
2024-11-28 15:59:10 +00:00
|
|
|
enum {
|
|
|
|
OPT_SNI_DOMAINS,
|
|
|
|
OPT_EXCLUDE_DOMAINS,
|
|
|
|
OPT_FAKE_SNI,
|
|
|
|
OPT_FAKING_TTL,
|
|
|
|
OPT_FAKING_STRATEGY,
|
|
|
|
OPT_FAKE_SNI_SEQ_LEN,
|
|
|
|
OPT_FAKE_SNI_TYPE,
|
|
|
|
OPT_FAKE_CUSTOM_PAYLOAD,
|
|
|
|
OPT_START_SECTION,
|
|
|
|
OPT_END_SECTION,
|
|
|
|
OPT_DAEMONIZE,
|
|
|
|
OPT_NOCLOSE,
|
|
|
|
OPT_SYSLOG,
|
|
|
|
OPT_FRAG,
|
|
|
|
OPT_FRAG_SNI_REVERSE,
|
|
|
|
OPT_FRAG_SNI_FAKED,
|
|
|
|
OPT_FRAG_MIDDLE_SNI,
|
|
|
|
OPT_FRAG_SNI_POS,
|
|
|
|
OPT_FK_WINSIZE,
|
|
|
|
OPT_TRACE,
|
|
|
|
OPT_QUIC_DROP,
|
|
|
|
OPT_SNI_DETECTION,
|
|
|
|
OPT_NO_IPV6,
|
|
|
|
OPT_FAKE_SEQ_OFFSET,
|
|
|
|
OPT_PACKET_MARK,
|
|
|
|
OPT_SYNFAKE,
|
|
|
|
OPT_SYNFAKE_LEN,
|
|
|
|
OPT_SEG2DELAY,
|
|
|
|
OPT_THREADS,
|
|
|
|
OPT_SILENT,
|
|
|
|
OPT_NO_GSO,
|
|
|
|
OPT_QUEUE_NUM,
|
2024-12-06 10:45:50 +00:00
|
|
|
OPT_UDP_MODE,
|
|
|
|
OPT_UDP_FAKE_SEQ_LEN,
|
|
|
|
OPT_UDP_FAKE_PAYLOAD_LEN,
|
|
|
|
OPT_UDP_FAKING_STRATEGY,
|
|
|
|
OPT_UDP_DPORT_FILTER,
|
|
|
|
OPT_UDP_FILTER_QUIC,
|
2024-12-06 15:25:43 +00:00
|
|
|
OPT_TLS_ENABLED,
|
2024-12-08 13:06:50 +00:00
|
|
|
OPT_CLS,
|
|
|
|
OPT_HELP,
|
|
|
|
OPT_VERSION,
|
2024-12-08 19:08:57 +00:00
|
|
|
OPT_CONNBYTES_LIMIT,
|
2024-11-28 15:59:10 +00:00
|
|
|
};
|
2024-08-10 23:10:18 +00:00
|
|
|
|
2024-08-10 18:44:04 +00:00
|
|
|
static struct option long_opt[] = {
|
2024-12-08 13:06:50 +00:00
|
|
|
{"help", 0, 0, OPT_HELP},
|
|
|
|
{"version", 0, 0, OPT_VERSION},
|
2024-08-10 23:10:18 +00:00
|
|
|
{"sni-domains", 1, 0, OPT_SNI_DOMAINS},
|
2024-09-03 18:22:17 +00:00
|
|
|
{"exclude-domains", 1, 0, OPT_EXCLUDE_DOMAINS},
|
2024-08-10 23:10:18 +00:00
|
|
|
{"fake-sni", 1, 0, OPT_FAKE_SNI},
|
2024-08-29 11:45:27 +00:00
|
|
|
{"synfake", 1, 0, OPT_SYNFAKE},
|
2024-08-29 12:49:01 +00:00
|
|
|
{"synfake-len", 1, 0, OPT_SYNFAKE_LEN},
|
2024-12-06 15:25:43 +00:00
|
|
|
{"tls", 1, 0, OPT_TLS_ENABLED},
|
2024-08-10 23:10:18 +00:00
|
|
|
{"fake-sni-seq-len", 1, 0, OPT_FAKE_SNI_SEQ_LEN},
|
2024-09-26 15:11:05 +00:00
|
|
|
{"fake-sni-type", 1, 0, OPT_FAKE_SNI_TYPE},
|
|
|
|
{"fake-custom-payload", 1, 0, OPT_FAKE_CUSTOM_PAYLOAD},
|
2024-08-10 23:10:18 +00:00
|
|
|
{"faking-strategy", 1, 0, OPT_FAKING_STRATEGY},
|
2024-08-27 20:23:54 +00:00
|
|
|
{"fake-seq-offset", 1, 0, OPT_FAKE_SEQ_OFFSET},
|
2024-08-10 23:10:18 +00:00
|
|
|
{"faking-ttl", 1, 0, OPT_FAKING_TTL},
|
|
|
|
{"frag", 1, 0, OPT_FRAG},
|
|
|
|
{"frag-sni-reverse", 1, 0, OPT_FRAG_SNI_REVERSE},
|
|
|
|
{"frag-sni-faked", 1, 0, OPT_FRAG_SNI_FAKED},
|
2024-08-17 09:51:53 +00:00
|
|
|
{"frag-middle-sni", 1, 0, OPT_FRAG_MIDDLE_SNI},
|
|
|
|
{"frag-sni-pos", 1, 0, OPT_FRAG_SNI_POS},
|
2024-08-11 21:45:30 +00:00
|
|
|
{"fk-winsize", 1, 0, OPT_FK_WINSIZE},
|
2024-08-13 17:48:35 +00:00
|
|
|
{"quic-drop", 0, 0, OPT_QUIC_DROP},
|
2024-08-14 23:31:48 +00:00
|
|
|
{"sni-detection", 1, 0, OPT_SNI_DETECTION},
|
2024-08-10 23:10:18 +00:00
|
|
|
{"seg2delay", 1, 0, OPT_SEG2DELAY},
|
2024-12-06 10:45:50 +00:00
|
|
|
{"udp-mode", 1, 0, OPT_UDP_MODE},
|
|
|
|
{"udp-fake-seq-len", 1, 0, OPT_UDP_FAKE_SEQ_LEN},
|
|
|
|
{"udp-fake-len", 1, 0, OPT_UDP_FAKE_PAYLOAD_LEN},
|
|
|
|
{"udp-faking-strategy", 1, 0, OPT_UDP_FAKING_STRATEGY},
|
|
|
|
{"udp-dport-filter", 1, 0, OPT_UDP_DPORT_FILTER},
|
|
|
|
{"udp-filter-quic", 1, 0, OPT_UDP_FILTER_QUIC},
|
2024-08-10 23:10:18 +00:00
|
|
|
{"threads", 1, 0, OPT_THREADS},
|
|
|
|
{"silent", 0, 0, OPT_SILENT},
|
2024-08-13 17:48:35 +00:00
|
|
|
{"trace", 0, 0, OPT_TRACE},
|
2024-08-10 23:10:18 +00:00
|
|
|
{"no-gso", 0, 0, OPT_NO_GSO},
|
2024-08-27 17:01:34 +00:00
|
|
|
{"no-ipv6", 0, 0, OPT_NO_IPV6},
|
2024-10-26 13:18:13 +00:00
|
|
|
{"daemonize", 0, 0, OPT_DAEMONIZE},
|
|
|
|
{"noclose", 0, 0, OPT_NOCLOSE},
|
2024-11-26 16:58:55 +00:00
|
|
|
{"syslog", 0, 0, OPT_SYSLOG},
|
2024-08-10 23:10:18 +00:00
|
|
|
{"queue-num", 1, 0, OPT_QUEUE_NUM},
|
2024-08-29 06:09:57 +00:00
|
|
|
{"packet-mark", 1, 0, OPT_PACKET_MARK},
|
2024-12-08 19:08:57 +00:00
|
|
|
{"connbytes-limit", 1, 0, OPT_CONNBYTES_LIMIT},
|
2024-10-13 20:31:26 +00:00
|
|
|
{"fbegin", 0, 0, OPT_START_SECTION},
|
|
|
|
{"fend", 0, 0, OPT_END_SECTION},
|
2024-12-08 13:06:50 +00:00
|
|
|
{"cls", 0, 0, OPT_CLS},
|
|
|
|
{0, 0, 0, 0},
|
2024-08-10 18:44:04 +00:00
|
|
|
};
|
|
|
|
|
2024-12-06 15:25:43 +00:00
|
|
|
void print_version(void) {
|
2024-10-28 22:09:23 +00:00
|
|
|
printf("youtubeUnblock"
|
|
|
|
#if defined(PKG_VERSION)
|
|
|
|
" " PKG_VERSION
|
|
|
|
#endif
|
|
|
|
"\n"
|
|
|
|
);
|
|
|
|
printf("Bypasses deep packet inspection systems that rely on SNI\n");
|
2024-08-11 18:43:32 +00:00
|
|
|
printf("\n");
|
2024-08-10 18:44:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void print_usage(const char *argv0) {
|
|
|
|
print_version();
|
|
|
|
|
|
|
|
printf("Usage: %s [ OPTIONS ] \n", argv0);
|
|
|
|
printf("Options:\n");
|
|
|
|
printf("\t--queue-num=<number of netfilter queue>\n");
|
|
|
|
printf("\t--sni-domains=<comma separated domain list>|all\n");
|
2024-09-03 18:22:17 +00:00
|
|
|
printf("\t--exclude-domains=<comma separated domain list>\n");
|
2024-12-06 15:25:43 +00:00
|
|
|
printf("\t--tls={enabled|disabled}\n");
|
2024-08-10 23:10:18 +00:00
|
|
|
printf("\t--fake-sni={1|0}\n");
|
|
|
|
printf("\t--fake-sni-seq-len=<length>\n");
|
2024-09-26 15:11:05 +00:00
|
|
|
printf("\t--fake-sni-type={default|random|custom}\n");
|
|
|
|
printf("\t--fake-custom-payload=<hex payload>\n");
|
2024-08-27 20:23:54 +00:00
|
|
|
printf("\t--fake-seq-offset=<offset>\n");
|
2024-08-10 23:10:18 +00:00
|
|
|
printf("\t--faking-ttl=<ttl>\n");
|
2024-09-13 16:04:48 +00:00
|
|
|
printf("\t--faking-strategy={randseq|ttl|tcp_check|pastseq|md5sum}\n");
|
2024-08-29 11:45:27 +00:00
|
|
|
printf("\t--synfake={1|0}\n");
|
2024-08-29 12:49:01 +00:00
|
|
|
printf("\t--synfake-len=<len>\n");
|
2024-08-10 18:44:04 +00:00
|
|
|
printf("\t--frag={tcp,ip,none}\n");
|
2024-08-10 23:10:18 +00:00
|
|
|
printf("\t--frag-sni-reverse={0|1}\n");
|
|
|
|
printf("\t--frag-sni-faked={0|1}\n");
|
2024-08-17 09:51:53 +00:00
|
|
|
printf("\t--frag-middle-sni={0|1}\n");
|
|
|
|
printf("\t--frag-sni-pos=<pos>\n");
|
2024-08-11 21:45:30 +00:00
|
|
|
printf("\t--fk-winsize=<winsize>\n");
|
2024-08-13 17:48:35 +00:00
|
|
|
printf("\t--quic-drop\n");
|
2024-08-14 23:31:48 +00:00
|
|
|
printf("\t--sni-detection={parse|brute}\n");
|
2024-08-10 18:44:04 +00:00
|
|
|
printf("\t--seg2delay=<delay>\n");
|
2024-12-06 10:45:50 +00:00
|
|
|
printf("\t--udp-mode={drop|fake}\n");
|
|
|
|
printf("\t--udp-fake-seq-len=<amount of faking packets sent>\n");
|
|
|
|
printf("\t--udp-fake-len=<size of upd fake>\n");
|
|
|
|
printf("\t--udp-faking-strategy={checksum|ttl}\n");
|
|
|
|
printf("\t--udp-dport-filter=<5,6,200-500>\n");
|
|
|
|
printf("\t--udp-filter-quic={disabled|all}\n");
|
2024-08-10 18:44:04 +00:00
|
|
|
printf("\t--threads=<threads number>\n");
|
2024-08-29 06:09:57 +00:00
|
|
|
printf("\t--packet-mark=<mark>\n");
|
2024-12-08 19:08:57 +00:00
|
|
|
printf("\t--connbytes-limit=<pkts>\n");
|
2024-08-10 18:44:04 +00:00
|
|
|
printf("\t--silent\n");
|
2024-08-13 17:48:35 +00:00
|
|
|
printf("\t--trace\n");
|
2024-08-10 18:44:04 +00:00
|
|
|
printf("\t--no-gso\n");
|
2024-08-27 17:01:34 +00:00
|
|
|
printf("\t--no-ipv6\n");
|
2024-10-26 13:18:13 +00:00
|
|
|
printf("\t--daemonize\n");
|
|
|
|
printf("\t--noclose\n");
|
2024-11-26 16:58:55 +00:00
|
|
|
printf("\t--syslog\n");
|
2024-10-13 20:31:26 +00:00
|
|
|
printf("\t--fbegin\n");
|
|
|
|
printf("\t--fend\n");
|
2024-08-10 18:44:04 +00:00
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
2024-12-08 13:06:50 +00:00
|
|
|
int yparse_args(int argc, char *argv[]) {
|
2024-08-10 18:44:04 +00:00
|
|
|
int opt;
|
2024-10-13 20:31:26 +00:00
|
|
|
int optIdx = 0;
|
2024-12-08 13:06:50 +00:00
|
|
|
optind=1, opterr=1, optreset=0;
|
2024-08-10 18:44:04 +00:00
|
|
|
long num;
|
2024-12-08 13:06:50 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
struct config_t rep_config;
|
|
|
|
ret = init_config(&rep_config);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
struct section_config_t *default_section = rep_config.last_section;
|
2024-08-10 18:44:04 +00:00
|
|
|
|
2024-12-08 13:06:50 +00:00
|
|
|
struct section_config_t *sect_config = rep_config.last_section;
|
|
|
|
int sect_i = 0;
|
|
|
|
sect_config->id = sect_i++;
|
2024-10-13 20:31:26 +00:00
|
|
|
|
|
|
|
#define SECT_ITER_DEFAULT 1
|
|
|
|
#define SECT_ITER_INSIDE 2
|
|
|
|
#define SECT_ITER_OUTSIDE 3
|
|
|
|
|
|
|
|
int section_iter = SECT_ITER_DEFAULT;
|
|
|
|
|
2024-12-08 13:06:50 +00:00
|
|
|
while ((opt = getopt_long(argc, argv, "", long_opt, &optIdx)) != -1) {
|
2024-08-10 18:44:04 +00:00
|
|
|
switch (opt) {
|
2024-12-08 13:06:50 +00:00
|
|
|
case OPT_CLS:
|
|
|
|
free_config(rep_config);
|
|
|
|
ret = init_config(&rep_config);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
default_section = rep_config.last_section;
|
|
|
|
|
|
|
|
sect_config = rep_config.last_section;
|
|
|
|
sect_i = 0;
|
|
|
|
sect_config->id = sect_i++;
|
|
|
|
section_iter = SECT_ITER_DEFAULT;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2024-10-13 20:31:26 +00:00
|
|
|
/* config_t scoped configs */
|
2024-12-08 13:06:50 +00:00
|
|
|
case OPT_HELP:
|
2024-08-12 12:22:04 +00:00
|
|
|
print_usage(argv[0]);
|
2024-12-08 13:06:50 +00:00
|
|
|
#ifndef KERNEL_SPACE
|
2024-08-12 12:22:04 +00:00
|
|
|
goto stop_exec;
|
2024-12-08 13:06:50 +00:00
|
|
|
#else
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
case OPT_VERSION:
|
2024-08-12 12:22:04 +00:00
|
|
|
print_version();
|
2024-12-08 13:06:50 +00:00
|
|
|
#ifndef KERNEL_SPACE
|
2024-08-12 12:22:04 +00:00
|
|
|
goto stop_exec;
|
2024-12-08 13:06:50 +00:00
|
|
|
#else
|
|
|
|
break;
|
|
|
|
#endif
|
2024-08-13 17:48:35 +00:00
|
|
|
case OPT_TRACE:
|
2024-12-08 13:06:50 +00:00
|
|
|
rep_config.verbose = 2;
|
2024-08-13 17:48:35 +00:00
|
|
|
break;
|
2024-08-12 12:22:04 +00:00
|
|
|
case OPT_SILENT:
|
2024-12-08 13:06:50 +00:00
|
|
|
rep_config.verbose = 0;
|
2024-08-12 12:22:04 +00:00
|
|
|
break;
|
|
|
|
case OPT_NO_GSO:
|
2024-12-08 13:06:50 +00:00
|
|
|
rep_config.use_gso = 0;
|
2024-08-12 12:22:04 +00:00
|
|
|
break;
|
2024-08-27 17:01:34 +00:00
|
|
|
case OPT_NO_IPV6:
|
2024-12-08 13:06:50 +00:00
|
|
|
rep_config.use_ipv6 = 0;
|
2024-08-27 17:01:34 +00:00
|
|
|
break;
|
2024-10-26 13:18:13 +00:00
|
|
|
case OPT_DAEMONIZE:
|
2024-12-08 13:06:50 +00:00
|
|
|
rep_config.daemonize = 1;
|
2024-10-26 13:18:13 +00:00
|
|
|
break;
|
|
|
|
case OPT_NOCLOSE:
|
2024-12-08 13:06:50 +00:00
|
|
|
rep_config.noclose = 1;
|
2024-10-26 13:18:13 +00:00
|
|
|
break;
|
2024-11-26 16:58:55 +00:00
|
|
|
case OPT_SYSLOG:
|
2024-12-08 13:06:50 +00:00
|
|
|
rep_config.syslog = 1;
|
2024-11-26 16:58:55 +00:00
|
|
|
break;
|
2024-10-13 20:31:26 +00:00
|
|
|
case OPT_THREADS:
|
|
|
|
num = parse_numeric_option(optarg);
|
|
|
|
if (errno != 0 || num < 0 || num > MAX_THREADS) {
|
|
|
|
goto invalid_opt;
|
|
|
|
}
|
|
|
|
|
2024-12-08 13:06:50 +00:00
|
|
|
rep_config.threads = num;
|
2024-08-13 17:48:35 +00:00
|
|
|
break;
|
2024-10-13 20:31:26 +00:00
|
|
|
case OPT_QUEUE_NUM:
|
|
|
|
num = parse_numeric_option(optarg);
|
|
|
|
if (errno != 0 || num < 0) {
|
|
|
|
goto invalid_opt;
|
2024-08-12 12:22:04 +00:00
|
|
|
}
|
|
|
|
|
2024-12-08 13:06:50 +00:00
|
|
|
rep_config.queue_start_num = num;
|
2024-08-14 23:31:48 +00:00
|
|
|
break;
|
2024-10-13 20:31:26 +00:00
|
|
|
case OPT_PACKET_MARK:
|
|
|
|
num = parse_numeric_option(optarg);
|
|
|
|
if (errno != 0 || num < 0) {
|
|
|
|
goto invalid_opt;
|
|
|
|
}
|
|
|
|
|
2024-12-08 13:06:50 +00:00
|
|
|
rep_config.mark = num;
|
2024-09-03 18:22:17 +00:00
|
|
|
break;
|
2024-12-08 19:08:57 +00:00
|
|
|
case OPT_CONNBYTES_LIMIT:
|
|
|
|
num = parse_numeric_option(optarg);
|
|
|
|
if (errno != 0 || num < 0) {
|
|
|
|
goto invalid_opt;
|
|
|
|
}
|
|
|
|
rep_config.connbytes_limit = num;
|
|
|
|
break;
|
2024-10-13 20:31:26 +00:00
|
|
|
case OPT_START_SECTION:
|
|
|
|
if (section_iter != SECT_ITER_DEFAULT && section_iter != SECT_ITER_OUTSIDE)
|
|
|
|
goto invalid_opt;
|
|
|
|
|
2024-12-08 13:06:50 +00:00
|
|
|
struct section_config_t *nsect;
|
|
|
|
ret = init_section_config(&nsect, rep_config.last_section);
|
|
|
|
if (ret < 0) {
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
rep_config.last_section->next = nsect;
|
|
|
|
rep_config.last_section = nsect;
|
|
|
|
sect_config = nsect;
|
|
|
|
sect_config->id = sect_i++;
|
2024-10-13 20:31:26 +00:00
|
|
|
section_iter = SECT_ITER_INSIDE;
|
|
|
|
|
|
|
|
break;
|
|
|
|
case OPT_END_SECTION:
|
|
|
|
if (section_iter != SECT_ITER_INSIDE)
|
2024-08-14 23:31:48 +00:00
|
|
|
goto invalid_opt;
|
2024-10-13 20:31:26 +00:00
|
|
|
|
|
|
|
section_iter = SECT_ITER_OUTSIDE;
|
2024-12-08 13:06:50 +00:00
|
|
|
sect_config = default_section;
|
2024-10-13 20:31:26 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
/* section_config_t scoped configs */
|
2024-12-06 15:25:43 +00:00
|
|
|
case OPT_TLS_ENABLED:
|
|
|
|
if (strcmp(optarg, "enabled") == 0) {
|
|
|
|
sect_config->tls_enabled = 1;
|
|
|
|
} else if (strcmp(optarg, "disabled") == 0) {
|
|
|
|
sect_config->tls_enabled = 0;
|
|
|
|
} else {
|
|
|
|
goto invalid_opt;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2024-10-13 20:31:26 +00:00
|
|
|
case OPT_SNI_DOMAINS:
|
2024-12-08 22:28:16 +00:00
|
|
|
free_sni_domains(sect_config->sni_domains);
|
2024-12-08 13:06:50 +00:00
|
|
|
sect_config->all_domains = 0;
|
2024-10-13 20:31:26 +00:00
|
|
|
if (!strcmp(optarg, "all")) {
|
|
|
|
sect_config->all_domains = 1;
|
2024-08-14 23:31:48 +00:00
|
|
|
}
|
|
|
|
|
2024-12-08 13:06:50 +00:00
|
|
|
ret = parse_sni_domains(§_config->sni_domains, optarg, strlen(optarg));
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
2024-10-13 20:31:26 +00:00
|
|
|
break;
|
|
|
|
case OPT_EXCLUDE_DOMAINS:
|
2024-12-08 22:28:16 +00:00
|
|
|
free_sni_domains(sect_config->exclude_sni_domains);
|
2024-12-08 13:06:50 +00:00
|
|
|
ret = parse_sni_domains(§_config->exclude_sni_domains, optarg, strlen(optarg));
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
|
2024-08-12 12:22:04 +00:00
|
|
|
break;
|
|
|
|
case OPT_FRAG:
|
|
|
|
if (strcmp(optarg, "tcp") == 0) {
|
2024-10-13 20:31:26 +00:00
|
|
|
sect_config->fragmentation_strategy = FRAG_STRAT_TCP;
|
2024-08-12 12:22:04 +00:00
|
|
|
} else if (strcmp(optarg, "ip") == 0) {
|
2024-10-13 20:31:26 +00:00
|
|
|
sect_config->fragmentation_strategy = FRAG_STRAT_IP;
|
2024-08-12 12:22:04 +00:00
|
|
|
} else if (strcmp(optarg, "none") == 0) {
|
2024-10-13 20:31:26 +00:00
|
|
|
sect_config->fragmentation_strategy = FRAG_STRAT_NONE;
|
2024-08-12 12:22:04 +00:00
|
|
|
} else {
|
|
|
|
goto invalid_opt;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
case OPT_FRAG_SNI_FAKED:
|
|
|
|
if (strcmp(optarg, "1") == 0) {
|
2024-10-13 20:31:26 +00:00
|
|
|
sect_config->frag_sni_faked = 1;
|
2024-08-12 12:22:04 +00:00
|
|
|
} else if (strcmp(optarg, "0") == 0) {
|
2024-10-13 20:31:26 +00:00
|
|
|
sect_config->frag_sni_faked = 0;
|
2024-08-12 12:22:04 +00:00
|
|
|
} else {
|
|
|
|
goto invalid_opt;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
case OPT_FRAG_SNI_REVERSE:
|
|
|
|
if (strcmp(optarg, "1") == 0) {
|
2024-10-13 20:31:26 +00:00
|
|
|
sect_config->frag_sni_reverse = 1;
|
2024-08-12 12:22:04 +00:00
|
|
|
} else if (strcmp(optarg, "0") == 0) {
|
2024-10-13 20:31:26 +00:00
|
|
|
sect_config->frag_sni_reverse = 0;
|
2024-08-12 12:22:04 +00:00
|
|
|
} else {
|
|
|
|
goto invalid_opt;
|
|
|
|
}
|
|
|
|
|
2024-08-17 09:51:53 +00:00
|
|
|
break;
|
|
|
|
case OPT_FRAG_MIDDLE_SNI:
|
|
|
|
if (strcmp(optarg, "1") == 0) {
|
2024-10-13 20:31:26 +00:00
|
|
|
sect_config->frag_middle_sni = 1;
|
2024-08-17 09:51:53 +00:00
|
|
|
} else if (strcmp(optarg, "0") == 0) {
|
2024-10-13 20:31:26 +00:00
|
|
|
sect_config->frag_middle_sni = 0;
|
2024-08-17 09:51:53 +00:00
|
|
|
} else {
|
|
|
|
goto invalid_opt;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
case OPT_FRAG_SNI_POS:
|
|
|
|
num = parse_numeric_option(optarg);
|
|
|
|
if (errno != 0 || num < 0) {
|
|
|
|
goto invalid_opt;
|
|
|
|
}
|
|
|
|
|
2024-10-13 20:31:26 +00:00
|
|
|
sect_config->frag_sni_pos = num;
|
2024-08-12 12:22:04 +00:00
|
|
|
break;
|
|
|
|
case OPT_FAKING_STRATEGY:
|
2024-08-16 19:47:55 +00:00
|
|
|
if (strcmp(optarg, "randseq") == 0) {
|
2024-10-13 20:31:26 +00:00
|
|
|
sect_config->faking_strategy = FAKE_STRAT_RAND_SEQ;
|
2024-08-12 12:22:04 +00:00
|
|
|
} else if (strcmp(optarg, "ttl") == 0) {
|
2024-10-13 20:31:26 +00:00
|
|
|
sect_config->faking_strategy = FAKE_STRAT_TTL;
|
2024-08-16 19:47:55 +00:00
|
|
|
} else if (strcmp(optarg, "tcp_check") == 0) {
|
2024-10-13 20:31:26 +00:00
|
|
|
sect_config->faking_strategy = FAKE_STRAT_TCP_CHECK;
|
2024-08-16 19:47:55 +00:00
|
|
|
} else if (strcmp(optarg, "pastseq") == 0) {
|
2024-10-13 20:31:26 +00:00
|
|
|
sect_config->faking_strategy = FAKE_STRAT_PAST_SEQ;
|
2024-09-13 16:04:48 +00:00
|
|
|
} else if (strcmp(optarg, "md5sum") == 0) {
|
2024-10-13 20:31:26 +00:00
|
|
|
sect_config->faking_strategy = FAKE_STRAT_TCP_MD5SUM;
|
2024-08-12 12:22:04 +00:00
|
|
|
} else {
|
|
|
|
goto invalid_opt;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
case OPT_FAKING_TTL:
|
|
|
|
num = parse_numeric_option(optarg);
|
|
|
|
if (errno != 0 || num < 0 || num > 255) {
|
|
|
|
goto invalid_opt;
|
|
|
|
}
|
|
|
|
|
2024-10-13 20:31:26 +00:00
|
|
|
sect_config->faking_ttl = num;
|
2024-08-12 12:22:04 +00:00
|
|
|
break;
|
2024-08-27 20:23:54 +00:00
|
|
|
case OPT_FAKE_SEQ_OFFSET:
|
|
|
|
num = parse_numeric_option(optarg);
|
2024-09-26 15:11:05 +00:00
|
|
|
if (errno != 0) {
|
2024-08-27 20:23:54 +00:00
|
|
|
goto invalid_opt;
|
|
|
|
}
|
2024-08-12 12:22:04 +00:00
|
|
|
|
2024-10-13 20:31:26 +00:00
|
|
|
sect_config->fakeseq_offset = num;
|
2024-08-27 20:23:54 +00:00
|
|
|
break;
|
2024-08-12 12:22:04 +00:00
|
|
|
case OPT_FAKE_SNI:
|
|
|
|
if (strcmp(optarg, "1") == 0) {
|
2024-10-13 20:31:26 +00:00
|
|
|
sect_config->fake_sni = 1;
|
2024-08-12 12:22:04 +00:00
|
|
|
} else if (strcmp(optarg, "0") == 0) {
|
2024-10-13 20:31:26 +00:00
|
|
|
sect_config->fake_sni = 0;
|
2024-08-12 12:22:04 +00:00
|
|
|
} else {
|
|
|
|
goto invalid_opt;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
case OPT_FAKE_SNI_SEQ_LEN:
|
|
|
|
num = parse_numeric_option(optarg);
|
|
|
|
if (errno != 0 || num < 0 || num > 255) {
|
|
|
|
goto invalid_opt;
|
|
|
|
}
|
|
|
|
|
2024-10-13 20:31:26 +00:00
|
|
|
sect_config->fake_sni_seq_len = num;
|
2024-09-26 15:11:05 +00:00
|
|
|
break;
|
|
|
|
case OPT_FAKE_SNI_TYPE:
|
|
|
|
if (strcmp(optarg, "default") == 0) {
|
2024-10-13 20:31:26 +00:00
|
|
|
sect_config->fake_sni_type = FAKE_PAYLOAD_DEFAULT;
|
2024-09-26 15:11:05 +00:00
|
|
|
} else if (strcmp(optarg, "random") == 0) {
|
2024-10-13 20:31:26 +00:00
|
|
|
sect_config->fake_sni_type = FAKE_PAYLOAD_RANDOM;
|
2024-09-26 15:11:05 +00:00
|
|
|
} else if (strcmp(optarg, "custom") == 0) {
|
2024-10-13 20:31:26 +00:00
|
|
|
sect_config->fake_sni_type = FAKE_PAYLOAD_CUSTOM;
|
2024-09-26 15:11:05 +00:00
|
|
|
} else {
|
|
|
|
goto invalid_opt;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2024-12-08 13:06:50 +00:00
|
|
|
case OPT_FAKE_CUSTOM_PAYLOAD:
|
2024-12-08 22:28:16 +00:00
|
|
|
SFREE(sect_config->fake_custom_pkt);
|
2024-09-26 15:11:05 +00:00
|
|
|
|
2024-12-08 13:06:50 +00:00
|
|
|
ret = parse_fake_custom_payload(optarg, §_config->fake_custom_pkt, §_config->fake_custom_pkt_sz);
|
|
|
|
if (ret == -EINVAL) {
|
|
|
|
goto invalid_opt;
|
|
|
|
} else if (ret < 0) {
|
|
|
|
goto error;
|
2024-09-28 20:06:45 +00:00
|
|
|
}
|
2024-12-08 13:06:50 +00:00
|
|
|
|
2024-09-26 15:11:05 +00:00
|
|
|
break;
|
2024-08-12 12:22:04 +00:00
|
|
|
case OPT_FK_WINSIZE:
|
|
|
|
num = parse_numeric_option(optarg);
|
|
|
|
if (errno != 0 || num < 0) {
|
|
|
|
goto invalid_opt;
|
|
|
|
}
|
|
|
|
|
2024-10-13 20:31:26 +00:00
|
|
|
sect_config->fk_winsize = num;
|
2024-08-29 11:45:27 +00:00
|
|
|
break;
|
|
|
|
|
2024-08-12 12:22:04 +00:00
|
|
|
case OPT_SEG2DELAY:
|
|
|
|
num = parse_numeric_option(optarg);
|
|
|
|
if (errno != 0 || num < 0) {
|
|
|
|
goto invalid_opt;
|
|
|
|
}
|
|
|
|
|
2024-10-13 20:31:26 +00:00
|
|
|
sect_config->seg2_delay = num;
|
2024-08-12 12:22:04 +00:00
|
|
|
break;
|
2024-10-13 20:31:26 +00:00
|
|
|
case OPT_QUIC_DROP:
|
2024-12-06 10:45:50 +00:00
|
|
|
sect_config->udp_filter_quic = UDP_FILTER_QUIC_ALL;
|
|
|
|
sect_config->udp_mode = UDP_MODE_DROP;
|
2024-08-12 12:22:04 +00:00
|
|
|
break;
|
2024-10-13 20:31:26 +00:00
|
|
|
case OPT_SNI_DETECTION:
|
|
|
|
if (strcmp(optarg, "parse") == 0) {
|
|
|
|
sect_config->sni_detection = SNI_DETECTION_PARSE;
|
|
|
|
} else if (strcmp(optarg, "brute") == 0) {
|
|
|
|
sect_config->sni_detection = SNI_DETECTION_BRUTE;
|
|
|
|
} else {
|
2024-08-29 06:09:57 +00:00
|
|
|
goto invalid_opt;
|
|
|
|
}
|
|
|
|
|
2024-10-13 22:16:46 +00:00
|
|
|
break;
|
|
|
|
case OPT_SYNFAKE:
|
|
|
|
if (strcmp(optarg, "1") == 0) {
|
|
|
|
sect_config->synfake = 1;
|
|
|
|
} else if (strcmp(optarg, "0") == 0) {
|
|
|
|
sect_config->synfake = 0;
|
|
|
|
} else {
|
|
|
|
goto invalid_opt;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
case OPT_SYNFAKE_LEN:
|
|
|
|
num = parse_numeric_option(optarg);
|
|
|
|
if (errno != 0 || num < 0) {
|
|
|
|
goto invalid_opt;
|
|
|
|
}
|
|
|
|
sect_config->synfake_len = num;
|
2024-12-06 10:45:50 +00:00
|
|
|
break;
|
|
|
|
case OPT_UDP_MODE:
|
|
|
|
if (strcmp(optarg, "drop") == 0) {
|
|
|
|
sect_config->udp_mode = UDP_MODE_DROP;
|
|
|
|
} else if (strcmp(optarg, "fake") == 0) {
|
|
|
|
sect_config->udp_mode = UDP_MODE_FAKE;
|
|
|
|
} else {
|
|
|
|
goto invalid_opt;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
case OPT_UDP_FAKING_STRATEGY:
|
|
|
|
if (strcmp(optarg, "checksum") == 0) {
|
|
|
|
sect_config->udp_faking_strategy = FAKE_STRAT_UDP_CHECK;
|
|
|
|
} else if (strcmp(optarg, "ttl") == 0) {
|
|
|
|
sect_config->udp_faking_strategy = FAKE_STRAT_TTL;
|
|
|
|
} else {
|
|
|
|
goto invalid_opt;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
case OPT_UDP_FAKE_SEQ_LEN:
|
|
|
|
num = parse_numeric_option(optarg);
|
|
|
|
if (errno != 0 || num < 0) {
|
|
|
|
goto invalid_opt;
|
|
|
|
}
|
|
|
|
|
|
|
|
sect_config->udp_fake_seq_len = num;
|
|
|
|
break;
|
|
|
|
case OPT_UDP_FAKE_PAYLOAD_LEN:
|
|
|
|
num = parse_numeric_option(optarg);
|
|
|
|
if (errno != 0 || num < 0 || num > 1300) {
|
|
|
|
goto invalid_opt;
|
|
|
|
}
|
|
|
|
|
|
|
|
sect_config->udp_fake_len = num;
|
|
|
|
break;
|
|
|
|
case OPT_UDP_DPORT_FILTER:
|
|
|
|
{
|
2024-12-08 13:06:50 +00:00
|
|
|
SFREE(sect_config->udp_dport_range);
|
|
|
|
if (parse_udp_dport_range(optarg, §_config->udp_dport_range, §_config->udp_dport_range_len) < 0) {
|
2024-12-06 10:45:50 +00:00
|
|
|
goto invalid_opt;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case OPT_UDP_FILTER_QUIC:
|
|
|
|
if (strcmp(optarg, "disabled") == 0) {
|
|
|
|
sect_config->udp_filter_quic = UDP_FILTER_QUIC_DISABLED;
|
|
|
|
} else if (strcmp(optarg, "all") == 0) {
|
|
|
|
sect_config->udp_filter_quic = UDP_FILTER_QUIC_ALL;
|
|
|
|
} else {
|
|
|
|
goto invalid_opt;
|
|
|
|
}
|
|
|
|
|
2024-08-29 06:09:57 +00:00
|
|
|
break;
|
2024-08-12 12:22:04 +00:00
|
|
|
default:
|
|
|
|
goto error;
|
2024-08-10 18:44:04 +00:00
|
|
|
}
|
2024-10-13 20:31:26 +00:00
|
|
|
|
2024-08-10 18:44:04 +00:00
|
|
|
}
|
|
|
|
|
2024-12-08 13:06:50 +00:00
|
|
|
struct config_t old_config = config;
|
|
|
|
config = rep_config;
|
|
|
|
free_config(old_config);
|
2024-08-10 18:44:04 +00:00
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
return 0;
|
2024-12-08 13:06:50 +00:00
|
|
|
|
2024-12-08 19:35:29 +00:00
|
|
|
#ifndef KERNEL_SPACE
|
2024-08-12 12:22:04 +00:00
|
|
|
stop_exec:
|
2024-12-08 13:06:50 +00:00
|
|
|
free_config(rep_config);
|
2024-08-10 18:44:04 +00:00
|
|
|
errno = 0;
|
|
|
|
return 1;
|
2024-12-08 19:35:29 +00:00
|
|
|
#endif
|
2024-08-12 12:22:04 +00:00
|
|
|
|
|
|
|
invalid_opt:
|
2024-08-12 01:52:03 +00:00
|
|
|
printf("Invalid option %s\n", long_opt[optIdx].name);
|
2024-12-08 13:06:50 +00:00
|
|
|
ret = -EINVAL;
|
2024-08-12 12:22:04 +00:00
|
|
|
error:
|
2024-12-08 13:06:50 +00:00
|
|
|
#ifndef KERNEL_SPACE
|
2024-08-10 18:44:04 +00:00
|
|
|
print_usage(argv[0]);
|
2024-12-08 13:06:50 +00:00
|
|
|
#endif
|
|
|
|
if (ret != -EINVAL) {
|
|
|
|
lgerror(ret, "Error thrown in %s\n", long_opt[optIdx].name);
|
|
|
|
}
|
|
|
|
|
|
|
|
errno = -ret;
|
|
|
|
free_config(rep_config);
|
2024-12-06 10:45:50 +00:00
|
|
|
return -errno;
|
2024-08-10 18:44:04 +00:00
|
|
|
}
|
2024-08-11 18:43:32 +00:00
|
|
|
|
2024-12-08 13:06:50 +00:00
|
|
|
#define print_cnf_raw(fmt, ...) do { \
|
|
|
|
sz = snprintf(buf_ptr, buf_sz, fmt, ##__VA_ARGS__); \
|
|
|
|
if (sz > buf_sz) { buf_sz = 0; } \
|
|
|
|
else { buf_sz -= sz; } \
|
|
|
|
buf_ptr += sz; \
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
#define print_cnf_buf(fmt, ...) print_cnf_raw(fmt " ", ##__VA_ARGS__)
|
|
|
|
// Returns written buffer size
|
|
|
|
static size_t print_config_section(const struct section_config_t *section, char *buffer, size_t buffer_size) {
|
|
|
|
char *buf_ptr = buffer;
|
|
|
|
size_t buf_sz = buffer_size;
|
|
|
|
size_t sz;
|
|
|
|
|
|
|
|
if (section->tls_enabled) {
|
|
|
|
print_cnf_buf("--tls=enabled");
|
|
|
|
if (section->sni_domains != NULL) {
|
|
|
|
print_cnf_raw("--sni-domains=");
|
|
|
|
for (struct domains_list *sne = section->sni_domains; sne != NULL; sne = sne->next) {
|
|
|
|
print_cnf_raw("%s,", sne->domain_name);
|
|
|
|
}
|
|
|
|
print_cnf_raw(" ");
|
|
|
|
}
|
|
|
|
if (section->exclude_sni_domains != NULL) {
|
|
|
|
print_cnf_raw("--exclude-domains=");
|
|
|
|
for (struct domains_list *sne = section->exclude_sni_domains; sne != NULL; sne = sne->next) {
|
|
|
|
print_cnf_raw("%s,", sne->domain_name);
|
|
|
|
}
|
|
|
|
print_cnf_raw(" ");
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(section->fragmentation_strategy) {
|
|
|
|
case FRAG_STRAT_IP:
|
|
|
|
print_cnf_buf("--frag=ip");
|
|
|
|
break;
|
|
|
|
case FRAG_STRAT_TCP:
|
|
|
|
print_cnf_buf("--frag=tcp");
|
|
|
|
break;
|
|
|
|
case FRAG_STRAT_NONE:
|
|
|
|
print_cnf_buf("--frag=none");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
print_cnf_buf("frag-sni-reverse=%d", section->frag_sni_reverse);
|
|
|
|
print_cnf_buf("frag-sni-faked=%d", section->frag_sni_faked);
|
|
|
|
print_cnf_buf("frag-middle-sni=%d", section->frag_middle_sni);
|
|
|
|
print_cnf_buf("frag-sni-pos=%d", section->frag_sni_pos);
|
|
|
|
print_cnf_buf("fk-winsize=%d", section->fk_winsize);
|
|
|
|
|
|
|
|
if (section->fake_sni) {
|
|
|
|
print_cnf_buf("--fake-sni=1");
|
|
|
|
print_cnf_buf("--fake-sni-seq-len=%d", section->fake_sni_seq_len);
|
|
|
|
switch(section->fake_sni_type) {
|
|
|
|
case FAKE_PAYLOAD_CUSTOM:
|
|
|
|
print_cnf_buf("--fake-sni-type=custom");
|
|
|
|
print_cnf_buf("--fake-custom-payload=<hidden>");
|
|
|
|
break;
|
|
|
|
case FAKE_PAYLOAD_RANDOM:
|
|
|
|
print_cnf_buf("--fake-sni-type=random");
|
|
|
|
break;
|
|
|
|
case FAKE_PAYLOAD_DEFAULT:
|
|
|
|
print_cnf_buf("--fake-sni-type=default");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(section->faking_strategy) {
|
|
|
|
case FAKE_STRAT_TTL:
|
|
|
|
print_cnf_buf("--faking-strategy=ttl");
|
|
|
|
print_cnf_buf("--faking-ttl=%d", section->faking_ttl);
|
|
|
|
break;
|
|
|
|
case FAKE_STRAT_RAND_SEQ:
|
|
|
|
print_cnf_buf("--faking-strategy=randseq");
|
|
|
|
break;
|
|
|
|
case FAKE_STRAT_TCP_CHECK:
|
|
|
|
print_cnf_buf("--faking-strategy=tcp_check");
|
|
|
|
break;
|
|
|
|
case FAKE_STRAT_TCP_MD5SUM:
|
|
|
|
print_cnf_buf("--faking-strategy=md5sum");
|
|
|
|
break;
|
|
|
|
case FAKE_STRAT_PAST_SEQ:
|
|
|
|
print_cnf_buf("--faking-strategy=pastseq");
|
|
|
|
print_cnf_buf("--fake-seq-offset=%d", section->fakeseq_offset);
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(section->sni_detection) {
|
|
|
|
case SNI_DETECTION_BRUTE:
|
|
|
|
print_cnf_buf("--sni_detection=brute");
|
|
|
|
break;
|
|
|
|
case SNI_DETECTION_PARSE:
|
|
|
|
print_cnf_buf("--sni_detection=parse");
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
print_cnf_buf("--seg2delay=%d", section->seg2_delay);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
print_cnf_buf("--tls=disabled");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (section->synfake) {
|
|
|
|
print_cnf_buf("--synfake=1");
|
|
|
|
print_cnf_buf("--synfake-len=%d", section->synfake_len);
|
|
|
|
} else {
|
|
|
|
print_cnf_buf("--synfake=0");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (section->udp_filter_quic == UDP_FILTER_QUIC_ALL && section->udp_mode == UDP_MODE_DROP) {
|
|
|
|
print_cnf_buf("--drop-quic");
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(section->udp_filter_quic) {
|
|
|
|
case UDP_FILTER_QUIC_ALL:
|
|
|
|
print_cnf_buf("--udp-filter-quic=all");
|
|
|
|
break;
|
|
|
|
case UDP_FILTER_QUIC_DISABLED:
|
|
|
|
print_cnf_buf("--udp-filter-quic=disabled");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (section->udp_dport_range_len != 0)
|
|
|
|
print_cnf_raw("--udp-dport-filter=");
|
|
|
|
for (int i = 0; i < section->udp_dport_range_len; i++) {
|
|
|
|
struct udp_dport_range range = section->udp_dport_range[i];
|
|
|
|
print_cnf_raw("%d-%d,", range.start, range.end);
|
|
|
|
}
|
|
|
|
print_cnf_raw(" ");
|
|
|
|
|
|
|
|
|
|
|
|
if (section->udp_filter_quic != UDP_FILTER_QUIC_DISABLED || section->udp_dport_range_len != 0) {
|
|
|
|
switch(section->udp_mode) {
|
|
|
|
case UDP_MODE_DROP:
|
|
|
|
print_cnf_buf("--udp-mode=drop");
|
|
|
|
break;
|
|
|
|
case UDP_MODE_FAKE:
|
|
|
|
print_cnf_buf("--udp-mode=fake");
|
|
|
|
print_cnf_buf("--udp-fake-seq-len=%d", section->udp_fake_seq_len);
|
|
|
|
{
|
|
|
|
switch(section->udp_faking_strategy) {
|
|
|
|
case FAKE_STRAT_UDP_CHECK:
|
|
|
|
print_cnf_buf("--udp-faking-strategy=checksum");
|
|
|
|
break;
|
|
|
|
case FAKE_STRAT_TTL:
|
|
|
|
print_cnf_buf("--udp-faking-strategy=ttl");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return buffer_size - buf_sz;
|
|
|
|
}
|
|
|
|
// Returns written buffer length
|
|
|
|
size_t print_config(char *buffer, size_t buffer_size) {
|
|
|
|
char *buf_ptr = buffer;
|
|
|
|
size_t buf_sz = buffer_size;
|
|
|
|
size_t sz;
|
|
|
|
|
|
|
|
#ifndef KERNEL_SPACE
|
|
|
|
print_cnf_buf("--queue-num=%d", config.queue_start_num);
|
|
|
|
print_cnf_buf("--threads=%d", config.threads);
|
|
|
|
#endif
|
|
|
|
print_cnf_buf("--mark=%d", config.mark);
|
|
|
|
|
|
|
|
#ifndef KERNEL_SPACE
|
|
|
|
if (config.daemonize) {
|
|
|
|
print_cnf_buf("--daemonize");
|
|
|
|
}
|
|
|
|
if (config.syslog) {
|
|
|
|
print_cnf_buf("--syslog");
|
|
|
|
}
|
|
|
|
if (config.noclose) {
|
|
|
|
print_cnf_buf("--noclose");
|
|
|
|
}
|
|
|
|
if (!config.use_gso) {
|
|
|
|
print_cnf_buf("--no-gso");
|
|
|
|
}
|
|
|
|
#endif
|
2024-12-08 19:08:57 +00:00
|
|
|
|
|
|
|
#ifdef KERNEL_SPACE
|
|
|
|
print_cnf_buf("--connbytes-limit=%d", config.connbytes_limit);
|
|
|
|
#endif
|
2024-12-08 13:06:50 +00:00
|
|
|
if (!config.use_ipv6) {
|
|
|
|
print_cnf_buf("--no-ipv6");
|
|
|
|
}
|
|
|
|
if (config.verbose == VERBOSE_TRACE) {
|
|
|
|
print_cnf_buf("--trace");
|
|
|
|
}
|
|
|
|
if (config.verbose == VERBOSE_INFO) {
|
|
|
|
print_cnf_buf("--silent");
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t wbuf_len = print_config_section(config.first_section, buf_ptr, buf_sz);
|
|
|
|
buf_ptr += wbuf_len;
|
|
|
|
buf_sz -= wbuf_len;
|
|
|
|
|
|
|
|
for (struct section_config_t *section = config.first_section->next;
|
|
|
|
section != NULL; section = section->next) {
|
|
|
|
print_cnf_buf("--fbegin");
|
|
|
|
wbuf_len = print_config_section(section, buf_ptr, buf_sz);
|
|
|
|
buf_ptr += wbuf_len;
|
|
|
|
buf_sz -= wbuf_len;
|
|
|
|
print_cnf_buf("--fend");
|
|
|
|
}
|
|
|
|
|
|
|
|
return buffer_size - buf_sz;
|
|
|
|
}
|
|
|
|
|
2024-12-06 15:25:43 +00:00
|
|
|
void print_welcome(void) {
|
2024-12-08 19:35:29 +00:00
|
|
|
char *welcome_message = malloc(4000);
|
|
|
|
if (welcome_message == NULL)
|
|
|
|
return;
|
|
|
|
|
2024-12-08 13:06:50 +00:00
|
|
|
size_t sz = print_config(welcome_message, 4000);
|
|
|
|
printf("Running with flags: %.*s\n", (int)sz, welcome_message);
|
2024-12-08 19:35:29 +00:00
|
|
|
free(welcome_message);
|
2024-12-08 13:06:50 +00:00
|
|
|
return;
|
|
|
|
/**
|
2024-11-26 16:58:55 +00:00
|
|
|
if (config.syslog) {
|
|
|
|
printf("Logging to system log\n");
|
|
|
|
}
|
2024-10-13 20:31:26 +00:00
|
|
|
if (config.use_gso) {
|
2024-11-26 16:58:55 +00:00
|
|
|
lginfo("GSO is enabled\n");
|
2024-08-11 18:43:32 +00:00
|
|
|
}
|
|
|
|
|
2024-10-13 20:31:26 +00:00
|
|
|
if (config.use_ipv6) {
|
2024-11-26 16:58:55 +00:00
|
|
|
lginfo("IPv6 is enabled\n");
|
2024-08-11 18:43:32 +00:00
|
|
|
} else {
|
2024-11-26 16:58:55 +00:00
|
|
|
lginfo("IPv6 is disabled\n");
|
2024-08-11 18:43:32 +00:00
|
|
|
}
|
2024-10-13 20:31:26 +00:00
|
|
|
|
2024-11-26 16:58:55 +00:00
|
|
|
lginfo("Detected %d config sections\n", config.custom_configs_len + 1);
|
|
|
|
lginfo("The sections will be processed in order they goes in this output\n");
|
2024-10-13 20:31:26 +00:00
|
|
|
|
|
|
|
ITER_CONFIG_SECTIONS(section) {
|
|
|
|
int section_number = CONFIG_SECTION_NUMBER(section);
|
2024-11-26 16:58:55 +00:00
|
|
|
lginfo("Section #%d\n", section_number);
|
2024-10-13 20:31:26 +00:00
|
|
|
|
2024-12-06 15:25:43 +00:00
|
|
|
if (!section->tls_enabled) {
|
|
|
|
lginfo("TCP TLS is disabled for section!\n");
|
|
|
|
}
|
2024-10-13 20:31:26 +00:00
|
|
|
switch (section->fragmentation_strategy) {
|
|
|
|
case FRAG_STRAT_TCP:
|
2024-11-26 16:58:55 +00:00
|
|
|
lginfo("Using TCP segmentation\n");
|
2024-10-13 20:31:26 +00:00
|
|
|
break;
|
|
|
|
case FRAG_STRAT_IP:
|
2024-11-26 16:58:55 +00:00
|
|
|
lginfo("Using IP fragmentation\n");
|
2024-10-13 20:31:26 +00:00
|
|
|
break;
|
|
|
|
default:
|
2024-11-26 16:58:55 +00:00
|
|
|
lginfo("SNI fragmentation is disabled\n");
|
2024-10-13 20:31:26 +00:00
|
|
|
break;
|
|
|
|
}
|
2024-08-11 18:43:32 +00:00
|
|
|
|
2024-10-13 20:31:26 +00:00
|
|
|
if (section->seg2_delay) {
|
2024-11-26 16:58:55 +00:00
|
|
|
lginfo("Some outgoing googlevideo request segments will be delayed for %d ms as of seg2_delay define\n", section->seg2_delay);
|
2024-10-13 20:31:26 +00:00
|
|
|
}
|
2024-08-11 18:43:32 +00:00
|
|
|
|
2024-10-13 20:31:26 +00:00
|
|
|
if (section->fake_sni) {
|
2024-11-26 16:58:55 +00:00
|
|
|
lginfo("Fake SNI will be sent before each target client hello\n");
|
2024-10-13 20:31:26 +00:00
|
|
|
} else {
|
2024-11-26 16:58:55 +00:00
|
|
|
lginfo("Fake SNI is disabled\n");
|
2024-10-13 20:31:26 +00:00
|
|
|
}
|
2024-08-11 18:43:32 +00:00
|
|
|
|
2024-10-13 20:31:26 +00:00
|
|
|
if (section->frag_sni_reverse) {
|
2024-11-26 16:58:55 +00:00
|
|
|
lginfo("Fragmentation Client Hello will be reversed\n");
|
2024-10-13 20:31:26 +00:00
|
|
|
}
|
2024-08-11 18:43:32 +00:00
|
|
|
|
2024-10-13 20:31:26 +00:00
|
|
|
if (section->frag_sni_faked) {
|
2024-11-26 16:58:55 +00:00
|
|
|
lginfo("Fooling packets will be sent near the original Client Hello\n");
|
2024-10-13 20:31:26 +00:00
|
|
|
}
|
2024-08-11 21:45:30 +00:00
|
|
|
|
2024-10-13 20:31:26 +00:00
|
|
|
if (section->fake_sni_seq_len > 1) {
|
2024-11-26 16:58:55 +00:00
|
|
|
lginfo("Faking sequence of length %d will be built as fake sni\n", section->fake_sni_seq_len);
|
2024-10-13 20:31:26 +00:00
|
|
|
}
|
2024-08-29 11:45:27 +00:00
|
|
|
|
2024-10-13 20:31:26 +00:00
|
|
|
switch (section->faking_strategy) {
|
|
|
|
case FAKE_STRAT_TTL:
|
2024-11-26 16:58:55 +00:00
|
|
|
lginfo("TTL faking strategy will be used with TTL %d\n", section->faking_ttl);
|
2024-10-13 20:31:26 +00:00
|
|
|
break;
|
|
|
|
case FAKE_STRAT_RAND_SEQ:
|
2024-11-26 16:58:55 +00:00
|
|
|
lginfo("Random seq faking strategy will be used\n");
|
|
|
|
lginfo("Fake seq offset set to %u\n", section->fakeseq_offset);
|
2024-10-13 20:31:26 +00:00
|
|
|
break;
|
|
|
|
case FAKE_STRAT_TCP_CHECK:
|
2024-11-26 16:58:55 +00:00
|
|
|
lginfo("TCP checksum faking strategy will be used\n");
|
2024-10-13 20:31:26 +00:00
|
|
|
break;
|
|
|
|
case FAKE_STRAT_PAST_SEQ:
|
2024-11-26 16:58:55 +00:00
|
|
|
lginfo("Past seq faking strategy will be used\n");
|
2024-10-13 20:31:26 +00:00
|
|
|
break;
|
|
|
|
case FAKE_STRAT_TCP_MD5SUM:
|
2024-11-26 16:58:55 +00:00
|
|
|
lginfo("md5sum faking strategy will be used\n");
|
2024-10-13 20:31:26 +00:00
|
|
|
break;
|
|
|
|
}
|
2024-08-11 18:43:32 +00:00
|
|
|
|
2024-10-13 20:31:26 +00:00
|
|
|
if (section->fk_winsize) {
|
2024-11-26 16:58:55 +00:00
|
|
|
lginfo("Response TCP window will be set to %d with the appropriate scale\n", section->fk_winsize);
|
2024-10-13 20:31:26 +00:00
|
|
|
}
|
2024-08-11 18:43:32 +00:00
|
|
|
|
2024-10-13 20:31:26 +00:00
|
|
|
if (section->synfake) {
|
2024-11-26 16:58:55 +00:00
|
|
|
lginfo("Fake SYN payload will be sent with each TCP request SYN packet\n");
|
2024-10-13 20:31:26 +00:00
|
|
|
}
|
2024-08-27 17:01:34 +00:00
|
|
|
|
2024-12-06 10:45:50 +00:00
|
|
|
if (section->udp_filter_quic && section->udp_mode == UDP_MODE_DROP) {
|
2024-11-26 16:58:55 +00:00
|
|
|
lginfo("All QUIC packets will be dropped\n");
|
2024-10-13 20:31:26 +00:00
|
|
|
}
|
2024-08-13 17:48:35 +00:00
|
|
|
|
2024-10-13 20:31:26 +00:00
|
|
|
if (section->sni_detection == SNI_DETECTION_BRUTE) {
|
2024-11-26 16:58:55 +00:00
|
|
|
lginfo("Server Name Extension will be parsed in the bruteforce mode\n");
|
2024-10-13 20:31:26 +00:00
|
|
|
}
|
2024-08-14 23:31:48 +00:00
|
|
|
|
2024-10-13 20:31:26 +00:00
|
|
|
if (section->all_domains) {
|
2024-11-26 16:58:55 +00:00
|
|
|
lginfo("All Client Hello will be targeted by youtubeUnblock!\n");
|
2024-10-13 20:31:26 +00:00
|
|
|
} else {
|
2024-11-26 16:58:55 +00:00
|
|
|
lginfo("Target sni domains: %s\n", section->domains_str);
|
2024-10-13 20:31:26 +00:00
|
|
|
}
|
2024-08-11 18:43:32 +00:00
|
|
|
}
|
2024-12-08 13:06:50 +00:00
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
int init_section_config(struct section_config_t **section, struct section_config_t *prev) {
|
|
|
|
struct section_config_t *def_section = NULL;
|
|
|
|
int ret;
|
|
|
|
#ifdef KERNEL_SPACE
|
|
|
|
def_section = kmalloc(sizeof(struct section_config_t), GFP_KERNEL);
|
|
|
|
#else
|
|
|
|
def_section = malloc(sizeof(struct section_config_t));
|
|
|
|
#endif
|
|
|
|
*def_section = (struct section_config_t)default_section_config;
|
|
|
|
def_section->prev = prev;
|
|
|
|
|
|
|
|
if (def_section == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
ret = parse_sni_domains(&def_section->sni_domains, default_snistr, sizeof(default_snistr));
|
|
|
|
if (ret < 0) {
|
|
|
|
free(def_section);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
def_section->fake_sni_pkt = fake_sni_old;
|
|
|
|
def_section->fake_sni_pkt_sz = sizeof(fake_sni_old) - 1;
|
|
|
|
|
|
|
|
*section = def_section;
|
|
|
|
return 0;
|
2024-08-11 18:43:32 +00:00
|
|
|
}
|
2024-10-12 09:19:33 +00:00
|
|
|
|
2024-12-08 13:06:50 +00:00
|
|
|
int init_config(struct config_t *config) {
|
|
|
|
struct config_t def_config = default_config_set;
|
|
|
|
int ret = 0;
|
|
|
|
struct section_config_t *def_section = NULL;
|
|
|
|
ret = init_section_config(&def_section, NULL);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
def_config.last_section = def_section;
|
|
|
|
def_config.first_section = def_section;
|
|
|
|
|
|
|
|
*config = def_config;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void free_config_section(struct section_config_t *section) {
|
|
|
|
lginfo("freeing %d\n", section->id);
|
|
|
|
if (section->udp_dport_range_len != 0) {
|
|
|
|
SFREE(section->udp_dport_range);
|
|
|
|
}
|
|
|
|
|
|
|
|
free_sni_domains(section->sni_domains);
|
|
|
|
section->sni_domains = NULL;
|
|
|
|
free_sni_domains(section->exclude_sni_domains);
|
|
|
|
section->exclude_sni_domains = NULL;
|
|
|
|
|
|
|
|
section->fake_custom_pkt_sz = 0;
|
|
|
|
SFREE(section->fake_custom_pkt);
|
|
|
|
|
|
|
|
free(section);
|
|
|
|
}
|
|
|
|
|
|
|
|
void free_config(struct config_t config) {
|
|
|
|
lginfo("freeing config\n");
|
|
|
|
for (struct section_config_t *sct = config.last_section; sct != NULL;) {
|
|
|
|
struct section_config_t *psct = sct->prev;
|
|
|
|
free_config_section(sct);
|
|
|
|
sct = psct;
|
|
|
|
}
|
|
|
|
}
|