Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For GUI For GoodbyeDPI #127

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/blackwhitelist.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ int blackwhitelist_load_list(const char *filename) {
if (strlen(line) > HOST_MAXLEN) {
printf("WARNING: host %s exceeds maximum host length and has not been added\n",
line);
fflush(stdout); // In order to properly work with GUI for GoodbyeDPI
continue;
}
if (strlen(line) < 4)
Expand All @@ -80,6 +81,7 @@ int blackwhitelist_load_list(const char *filename) {
free(line);
if (!blackwhitelist) return FALSE;
printf("Loaded %d hosts from file %s\n", cnt, filename);
fflush(stdout); // In order to properly work with GUI for GoodbyeDPI
fclose(fp);
return TRUE;
}
Expand Down
2 changes: 2 additions & 0 deletions src/dnsredir.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,14 @@ void flush_dns_cache() {
if (dnsapi == NULL)
{
printf("Can't load dnsapi.dll to flush DNS cache!\n");
fflush(stdout); // In order to properly work with GUI for GoodbyeDPI
exit(EXIT_FAILURE);
}

DnsFlushResolverCache = (void*)GetProcAddress(dnsapi, "DnsFlushResolverCache");
if (DnsFlushResolverCache == NULL || !DnsFlushResolverCache())
printf("Can't flush DNS cache!");
fflush(stdout); // In order to properly work with GUI for GoodbyeDPI
FreeLibrary(dnsapi);
}

Expand Down
49 changes: 33 additions & 16 deletions src/goodbyedpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,8 @@ WINSOCK_API_LINKAGE INT WSAAPI inet_pton(INT Family, LPCSTR pStringBuf, PVOID pA
"(tcp.SrcPort == 443 or tcp.SrcPort == 80) and tcp.Rst and " \
DIVERT_NO_LOCALNETSv4_SRC

#define SET_HTTP_FRAGMENT_SIZE_OPTION(fragment_size) do { \
if (!http_fragment_size) { \
http_fragment_size = (unsigned int)fragment_size; \
} \
else if (http_fragment_size != (unsigned int)fragment_size) { \
printf( \
"WARNING: HTTP fragment size is already set to %d, not changing.\n", \
http_fragment_size \
); \
} \
} while (0)
#define SET_HTTP_FRAGMENT_SIZE_OPTION(fragment_size) do{ if (!http_fragment_size) { http_fragment_size = (unsigned int)fragment_size; }else if (http_fragment_size != (unsigned int)fragment_size) { printf("WARNING: HTTP fragment size is already set to %d, not changing.\n", http_fragment_size );fflush(stdout); } }while(0)


static int running_from_service = 0;
static HANDLE filters[MAX_FILTERS];
Expand Down Expand Up @@ -142,10 +133,15 @@ static void add_filter_str(int proto, int port) {

strcpy(new_filter, current_filter);
if (proto == IPPROTO_UDP)
{
sprintf(&(new_filter[strlen(new_filter)]), udp, port, port);
fflush(stdout); // In order to properly work with GUI for GoodbyeDPI
}
else
{
sprintf(&(new_filter[strlen(new_filter)]), tcp, port, port);

fflush(stdout); // In order to properly work with GUI for GoodbyeDPI
}
filter_string = new_filter;
free(current_filter);
}
Expand All @@ -156,6 +152,7 @@ static void add_ip_id_str(int id) {
char *addfilter = malloc(strlen(ipid) + 16);

sprintf(addfilter, ipid, id);
fflush(stdout); // In order to properly work with GUI for GoodbyeDPI

newstr = repl_str(filter_string, IPID_TEMPLATE, addfilter);
free(filter_string);
Expand Down Expand Up @@ -200,6 +197,7 @@ unsigned short int atousi(const char *str, const char *msg) {

if(res > limitValue) {
puts(msg);
fflush(stdout);
exit(EXIT_FAILURE);
}
return (unsigned short int)res;
Expand All @@ -218,6 +216,7 @@ static HANDLE init(char *filter, UINT64 flags) {
NULL, errorcode, MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT),
(LPTSTR)&errormessage, 0, NULL);
printf("Error opening filter: %s", errormessage);
fflush(stdout); // In order to properly work with GUI for GoodbyeDPI
LocalFree(errormessage);
if (errorcode == 577)
printf("Windows Server 2016 systems must have secure boot disabled to be "
Expand All @@ -229,6 +228,7 @@ static HANDLE init(char *filter, UINT64 flags) {
"Most probably, you don't have security patches installed and anyone in you LAN or "
"public Wi-Fi network can get full access to your computer (MS17-010 and others).\n"
"You should install updates IMMEDIATELY.\n");
fflush(stdout); // In order to properly work with GUI for GoodbyeDPI
return NULL;
}

Expand Down Expand Up @@ -338,7 +338,7 @@ static PVOID find_http_method_end(const char *pkt, unsigned int http_frag, int *
return NULL;
}

int main(int argc, char *argv[]) {
int main(int argc, char *argv[]){
static enum packet_type_e {
unknown,
ipv4_tcp, ipv4_tcp_data, ipv4_udp_data,
Expand Down Expand Up @@ -414,6 +414,7 @@ int main(int argc, char *argv[]) {
": Passive DPI blocker and Active DPI circumvention utility\n"
"https://github.com/ValdikSS/GoodbyeDPI\n\n"
);
fflush(stdout); // In order to properly work with GUI for GoodbyeDPI

if (argc == 1) {
/* enable mode -1 by default */
Expand All @@ -424,7 +425,7 @@ int main(int argc, char *argv[]) {
= do_fragment_http_persistent_nowait = 1;
}

while ((opt = getopt_long(argc, argv, "1234prsaf:e:mwk:n", long_options, NULL)) != -1) {
while ((opt = getopt_long(argc, argv, "1234prsaf:e:mwk:n", long_options, NULL)) != -1){
switch (opt) {
case '1':
do_passivedpi = do_host = do_host_removespace \
Expand Down Expand Up @@ -486,6 +487,7 @@ int main(int argc, char *argv[]) {
i = atoi(optarg);
if (i <= 0 || i > 65535) {
printf("Port parameter error!\n");
fflush(stdout); // In order to properly work with GUI for GoodbyeDPI
exit(EXIT_FAILURE);
}
if (i != 80 && i != 443)
Expand All @@ -505,13 +507,15 @@ int main(int argc, char *argv[]) {
do_dnsv4_redirect = 1;
if (inet_pton(AF_INET, optarg, &dnsv4_addr) != 1) {
puts("DNS address parameter error!");
fflush(stdout);
exit(EXIT_FAILURE);
}
add_filter_str(IPPROTO_UDP, 53);
flush_dns_cache();
break;
}
puts("DNS address parameter error!");
fflush(stdout);
exit(EXIT_FAILURE);
break;
case '!':
Expand All @@ -521,20 +525,23 @@ int main(int argc, char *argv[]) {
do_dnsv6_redirect = 1;
if (inet_pton(AF_INET6, optarg, dnsv6_addr.s6_addr) != 1) {
puts("DNS address parameter error!");
fflush(stdout);
exit(EXIT_FAILURE);
}
add_filter_str(IPPROTO_UDP, 53);
flush_dns_cache();
break;
}
puts("DNS address parameter error!");
fflush(stdout);
exit(EXIT_FAILURE);
break;
case 'g':
if (!do_dnsv4_redirect) {
puts("--dns-port should be used with --dns-addr!\n"
"Make sure you use --dns-addr and pass it before "
"--dns-port");
fflush(stdout);
exit(EXIT_FAILURE);
}
dnsv4_port = atousi(optarg, "DNS port parameter error!");
Expand All @@ -548,6 +555,7 @@ int main(int argc, char *argv[]) {
puts("--dnsv6-port should be used with --dnsv6-addr!\n"
"Make sure you use --dnsv6-addr and pass it before "
"--dnsv6-port");
fflush(stdout);
exit(EXIT_FAILURE);
}
dnsv6_port = atousi(optarg, "DNS port parameter error!");
Expand All @@ -563,6 +571,7 @@ int main(int argc, char *argv[]) {
do_blacklist = 1;
if (!blackwhitelist_load_list(optarg)) {
printf("Can't load blacklist from file!\n");
fflush(stdout); // In order to properly work with GUI for GoodbyeDPI
exit(EXIT_FAILURE);
}
break;
Expand Down Expand Up @@ -592,6 +601,7 @@ int main(int argc, char *argv[]) {
" -2 -p -r -s -f 2 -k 2 -n -e 40 (better speed for HTTPS yet still compatible)\n"
" -3 -p -r -s -e 40 (better speed for HTTP and HTTPS)\n"
" -4 -p -r -s (best speed)");
fflush(stdout);
exit(EXIT_FAILURE);
}
}
Expand All @@ -612,14 +622,17 @@ int main(int argc, char *argv[]) {
do_http_allports, do_fragment_http_persistent_nowait, do_dnsv4_redirect,
do_dnsv6_redirect
);
fflush(stdout); // In order to properly work with GUI for GoodbyeDPI

if (do_fragment_http && http_fragment_size > 2) {
printf("WARNING: HTTP fragmentation values > 2 are not fully compatible "
"with other options. Please use values <= 2 or disable HTTP fragmentation "
"completely.\n");
fflush(stdout); // In order to properly work with GUI for GoodbyeDPI
}

printf("\nOpening filter\n");
fflush(stdout); // In order to properly work with GUI for GoodbyeDPI
finalize_filter_strings();
filter_num = 0;

Expand Down Expand Up @@ -648,9 +661,10 @@ int main(int argc, char *argv[]) {
}

printf("Filter activated!\n");
fflush(stdout); // In order to properly work with GUI for GoodbyeDPI
signal(SIGINT, sigint_handler);

while (1) {
while(1){
if (WinDivertRecv(w_filter, packet, sizeof(packet), &addr, &packetLen)) {
debug("Got %s packet, len=%d!\n", addr.Direction ? "inbound" : "outbound",
packetLen);
Expand Down Expand Up @@ -936,6 +950,7 @@ int main(int argc, char *argv[]) {
if (do_dns_verb && !should_reinject) {
printf("[DNS] Error handling incoming packet: srcport = %hu, dstport = %hu\n",
ntohs(ppUdpHdr->SrcPort), ntohs(ppUdpHdr->DstPort));
fflush(stdout); // In order to properly work with GUI for GoodbyeDPI
}
}
}
Expand Down Expand Up @@ -968,6 +983,7 @@ int main(int argc, char *argv[]) {
if (do_dns_verb && !should_reinject) {
printf("[DNS] Error handling outgoing packet: srcport = %hu, dstport = %hu\n",
ntohs(ppUdpHdr->SrcPort), ntohs(ppUdpHdr->DstPort));
fflush(stdout); // In order to properly work with GUI for GoodbyeDPI
}
}
}
Expand All @@ -984,7 +1000,8 @@ int main(int argc, char *argv[]) {
else {
// error, ignore
printf("Error receiving packet!\n");
fflush(stdout); // In order to properly work with GUI for GoodbyeDPI
break;
}
}
}
}