From 5bb0e65d20626a276260ebe141b6ce3953235358 Mon Sep 17 00:00:00 2001 From: ValdikSS Date: Tue, 16 May 2017 22:07:40 +0300 Subject: [PATCH] Initial commit --- Makefile | 28 +++++ README.md | 38 ++++++ goodbyedpi-rc.rc | 2 + goodbyedpi.c | 256 ++++++++++++++++++++++++++++++++++++++++ goodbyedpi.exe.manifest | 12 ++ icon.ico | Bin 0 -> 11454 bytes 6 files changed, 336 insertions(+) create mode 100644 Makefile create mode 100644 README.md create mode 100644 goodbyedpi-rc.rc create mode 100644 goodbyedpi.c create mode 100644 goodbyedpi.exe.manifest create mode 100644 icon.ico diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..6c2db1d --- /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 0000000..511c3cc --- /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 0000000..f820576 --- /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 0000000..3c11956 --- /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 0000000..830d7de --- /dev/null +++ b/goodbyedpi.exe.manifest @@ -0,0 +1,12 @@ + + + + Divert + + + + + + + + diff --git a/icon.ico b/icon.ico new file mode 100644 index 0000000000000000000000000000000000000000..3e40fe0e303dc5e463b0df72909677871ae377e2 GIT binary patch literal 11454 zcmcIq30zdy)juGUnMY(8t++SihD!Jn71yuCjxng!M8(}06R=fd4Rxtfv6_Nt)r43V zI(*K^j6z5>#5HJ5Fn(Z6qT<@bHEO^{jaaIPGB|JOecw6vy_tEl@CE(ZI}Y!>^UnRB z|2^lf&jAR*PjWKgUma}wFMyT+&>g?1f>QjFzM;}S1fU~?!n0@)jdBmP?t|Z7;C&yw zH{tca@tT0wA$W~PtRbL*L7;_UVF1IMXknBFuUdda{0@2QX?QstU|e_z3=<+?OjCeS zO~YXL(*{V?Yhj`RZ43fTjtqy9`W7(dX8@xOt>E=24J0;e4KEvvkl4ZiW1^Zva$A63 zw+9&CswE`0d(m)u zjP49mJI2E6UAn@;9so&QyFqf-?l7(Uvyj#Y?_=U%M(lGi^IjSa+2bQ%(Xd}Z+R#y8eGOpou+fk+u?75b z#LKYsm64G4${5HPod}zgBO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