diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..6c2db1d5 --- /dev/null +++ b/Makefile @@ -0,0 +1,28 @@ +TARGET = goodbyedpi.exe +LIBS = -L ../binary -lWinDivert -lws2_32 +CC = x86_64-w64-mingw32-gcc +CCWINDRES = x86_64-w64-mingw32-windres +CFLAGS = -Wall -I ../../include -L ../binary -O2 + +.PHONY: default all clean + +default: manifest $(TARGET) +all: default + +OBJECTS = $(patsubst %.c, %.o, $(wildcard *.c)) goodbyedpi-rc.o +HEADERS = $(wildcard *.h) + +%.o: %.c $(HEADERS) + $(CC) $(CFLAGS) -c $< -o $@ + +manifest: + $(CCWINDRES) goodbyedpi-rc.rc goodbyedpi-rc.o + +.PRECIOUS: $(TARGET) $(OBJECTS) + +$(TARGET): $(OBJECTS) + $(CC) $(OBJECTS) -Wall $(LIBS) -s -o $@ + +clean: + -rm -f *.o + -rm -f $(TARGET) diff --git a/README.md b/README.md new file mode 100644 index 00000000..511c3ccf --- /dev/null +++ b/README.md @@ -0,0 +1,38 @@ +GoodbyeDPI — Passive Deep Packet Inspection blocker and Active DPI circumvention utility +========================= + +This software designed to bypass Deep Packet Inspection systems found in many Internet Service Providers which block access to certain websites. + +It handles DPI connected using optical splitter or port mirroring (**Passive DPI**) which do not block any data but just replying faster then requested destination, and **Active DPI** connected in sequence. + +**Windows 7, 8, 8.1 and 10** with administrator privileges required. + +# How to use + +Download [latest version from Releases page](https://github.com/ValdikSS/GoodbyeDPI/releases) and run. + +# How does it work + +### Passive DPI + +Most Passive DPI send HTTP 301 Redirect if you try to access blocked website over HTTP and TCP Reset in case of HTTPS, faster then destination website. Packets sent by DPI have always have IP Identification field equal to `0x0000` or `0x0001`, as seen with Russian providers. These packets are blocked by GoodbyeDPI. + +### Active DPI + +Active DPI is more tricky to fool. Currently the software uses 3 methods to circumvent Active DPI: + +* TCP-level fragmentation for first data packet +* Replacing `Host` header with `hoSt` +* Removing space between header name and value in `Host` header + +These methods do not break any website as are fully compatible with TCP and HTTP standards, yet it's sufficient to prevent DPI data classification and to circumvent censorship. + +# Similar projects + +[zapret](https://github.com/bol-van/zapret) by @bol-van (for Linux). + +# Kudos + +Thanks @basil00 for [WinDivert](https://github.com/basil00/Divert). That's the main part of this program. + +Thanks for every [BlockCheck](https://github.com/ValdikSS/blockcheck) contributor. It would be impossible to understand DPI behaviour without this utility. diff --git a/goodbyedpi-rc.rc b/goodbyedpi-rc.rc new file mode 100644 index 00000000..f8205760 --- /dev/null +++ b/goodbyedpi-rc.rc @@ -0,0 +1,2 @@ +1 24 "goodbyedpi.exe.manifest" +id ICON "icon.ico" diff --git a/goodbyedpi.c b/goodbyedpi.c new file mode 100644 index 00000000..3c119562 --- /dev/null +++ b/goodbyedpi.c @@ -0,0 +1,256 @@ +/* + * GoodbyeDPI — Passive DPI blocker and Active DPI circumvention utility. + */ + +#include +#include +#include +#include +#include +#include +#include "windivert.h" + +#define die() do { printf("Something went wrong!\n" \ + "Make sure you're running this program with administrator privileges\n"); \ + sleep(10); exit(1); } while (0) + +#define MAX_FILTERS 4 +#define MAX_PACKET_SIZE 1516 +#define IPV4_HDR_LEN 20 +#define TCP_HDR_LEN 20 +#define IPV4_TOTALLEN_OFFSET 2 +#define TCP_WINDOWSIZE_OFFSET 14 + +static HANDLE filters[MAX_FILTERS]; +static int filter_num = 0; +static const char *http_redirect_10 = "HTTP/1.0 30"; +static const char *http_redirect_11 = "HTTP/1.1 30"; +static const char *http_host_find = "\r\nHost: "; +static const char *http_host_replace = "\r\nhoSt: "; +/*static const char *blocklist[] = { + "warning.rt.ru", +};*/ + +static char* dumb_memmem(char* haystack, int hlen, char* needle, int nlen) { + // naive implementation + if (nlen > hlen) return 0; + int i; + for (i=0; i 16) { + /* If INBOUND packet with DATA (tcp.Ack) */ + + /* Drop packets from blocklist */ + /* for (i = 0; i < sizeof(blocklist) / sizeof(*blocklist); i++) { + if (dumb_memmem(packet_data, packet_dataLen, (char*)blocklist[i], + strlen(blocklist[i])) != NULL) { + printf("Dropping packet!\n"); + dropped = 1; + break; + } + } */ + + /* Drop packets from filter with HTTP 30x Redirect */ + if (do_passivedpi && find_passivedpi_redirect(packet_data)) { + //printf("Dropping HTTP Redirect packet!\n"); + should_reinject = 0; + } + } + /* Handle OUTBOUND packet, search for Host header */ + else if (addr.Direction == WINDIVERT_DIRECTION_OUTBOUND && + packet_dataLen > 16 && ppTcpHdr->DstPort == htons(80)) { + if (do_host || do_host_removespace) { + data_addr = find_host_header(packet_data, packet_dataLen); + } + + if (do_host && data_addr) { + /* Replace "Host: " with "hoSt: " */ + memcpy(data_addr, http_host_replace, strlen(http_host_replace)); + //printf("Replaced Host header!\n"); + } + + if (do_host_removespace && data_addr) { + host_addr = data_addr + strlen(http_host_find); + + data_addr_rn = dumb_memmem(host_addr, + packet_dataLen - ((PVOID)host_addr - packet_data), + "\r\n", 2); + if (data_addr_rn) { + host_len = data_addr_rn - host_addr; + fromhost_uptoend_len = packet_dataLen - ((PVOID)host_addr - packet_data); + if (host_len <= 64) { + /* Move memory left by 1 byte and reduce packet size for 1 byte */ + memmove(host_addr - 1, host_addr, fromhost_uptoend_len); + /* Reduce "Total Length" in IP header by 1 byte */ + *(uint16_t*)(packet + IPV4_TOTALLEN_OFFSET) = ntohs( + htons(*(uint16_t*)(packet + IPV4_TOTALLEN_OFFSET)) - 1); + /* Reduce packetLen by 1 byte */ + packetLen--; + //printf("Replaced Host header!\n"); + } + } + } + if (do_host || do_host_removespace) { + WinDivertHelperCalcChecksums(packet, packetLen, 0); + } + } + } + /* Else if we got TCP packet without data */ + else if (WinDivertHelperParsePacket(packet, packetLen, &ppIpHdr, + NULL, NULL, NULL, &ppTcpHdr, NULL, NULL, NULL)) { + /* If we got SYN+ACK packet */ + if (addr.Direction == WINDIVERT_DIRECTION_INBOUND && + ppTcpHdr->Syn == 1) { + if (do_fragment) { + //printf("Changing Window Size!\n"); + change_window_size(packet); + WinDivertHelperCalcChecksums(packet, packetLen, 0); + } + } + } + + if (should_reinject) { + //printf("Re-injecting!\n"); + WinDivertSend(w_filter, packet, packetLen, &addr, NULL); + } + } + else { + // error, ignore + printf("Error receiving packet!\n"); + break; + } + } +} diff --git a/goodbyedpi.exe.manifest b/goodbyedpi.exe.manifest new file mode 100644 index 00000000..830d7deb --- /dev/null +++ b/goodbyedpi.exe.manifest @@ -0,0 +1,12 @@ + + + + Divert + + + + + + + + diff --git a/icon.ico b/icon.ico new file mode 100644 index 00000000..3e40fe0e Binary files /dev/null and b/icon.ico differ