mirror of
https://github.com/ValdikSS/GoodbyeDPI.git
synced 2025-12-17 12:54:36 +03:00
Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2fe377a23f | ||
|
|
b74c974235 | ||
|
|
96fb5f9516 | ||
|
|
c1ca4f9804 | ||
|
|
13261e1a92 | ||
|
|
4387e7c690 | ||
|
|
08902b9a57 | ||
|
|
f5ac7c0d67 | ||
|
|
2a5e4a071b | ||
|
|
ae3abff0b2 | ||
|
|
d9e27f193c | ||
|
|
c721ab0506 |
27
README.md
27
README.md
@@ -38,7 +38,7 @@ Use `goodbyedpi.exe -4` if it works for your ISP's DPI. This is the fastest mode
|
|||||||
|
|
||||||
### Passive DPI
|
### Passive DPI
|
||||||
|
|
||||||
Most Passive DPI send HTTP 302 Redirect if you try to access blocked website over HTTP and TCP Reset in case of HTTPS, faster than destination website. Packets sent by DPI have always have IP Identification field equal to `0x0000` or `0x0001`, as seen with Russian providers. These packets, if they redirect you to another website (censorship page), are blocked by GoodbyeDPI.
|
Most Passive DPI send HTTP 302 Redirect if you try to access blocked website over HTTP and TCP Reset in case of HTTPS, faster than destination website. Packets sent by DPI always have IP Identification field equal to `0x0000` or `0x0001`, as seen with Russian providers. These packets, if they redirect you to another website (censorship page), are blocked by GoodbyeDPI.
|
||||||
|
|
||||||
### Active DPI
|
### Active DPI
|
||||||
|
|
||||||
@@ -49,7 +49,7 @@ Active DPI is more tricky to fool. Currently the software uses 4 methods to circ
|
|||||||
* Removing space between header name and value in `Host` header
|
* Removing space between header name and value in `Host` header
|
||||||
* Adding additional space between HTTP Method (GET, POST etc) and URI
|
* Adding additional space between HTTP Method (GET, POST etc) and URI
|
||||||
|
|
||||||
These methods should 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. Additional space may break some websites, although it's acceptable by HTTP/1.1 specification (see 19.3 Tolerant Applications).
|
These methods should not break any website as they're fully compatible with TCP and HTTP standards, yet it's sufficient to prevent DPI data classification and to circumvent censorship. Additional space may break some websites, although it's acceptable by HTTP/1.1 specification (see 19.3 Tolerant Applications).
|
||||||
|
|
||||||
The program loads WinDivert driver which uses Windows Filtering Platform to set filters and redirect packets to the userspace. It's running as long as console window is visible and terminates when you close the window.
|
The program loads WinDivert driver which uses Windows Filtering Platform to set filters and redirect packets to the userspace. It's running as long as console window is visible and terminates when you close the window.
|
||||||
|
|
||||||
@@ -65,6 +65,29 @@ And for x86_64:
|
|||||||
|
|
||||||
`make CPREFIX=x86_64-w64-mingw32 WINDIVERTHEADERS=/path/to/windivert/include WINDIVERTLIBS=/path/to/windivert/amd64`
|
`make CPREFIX=x86_64-w64-mingw32 WINDIVERTHEADERS=/path/to/windivert/include WINDIVERTLIBS=/path/to/windivert/amd64`
|
||||||
|
|
||||||
|
# How to install as Windows Service
|
||||||
|
|
||||||
|
One way is using an [srvstart](http://www.rozanski.org.uk/software) program.
|
||||||
|
Unpack it to `goodbyedpi` directory and create 3 files:
|
||||||
|
|
||||||
|
*goodbyedpi.ini*
|
||||||
|
```INI
|
||||||
|
[GoodByeDPI]
|
||||||
|
startup=goodbyedpi.exe
|
||||||
|
shutdown_method=winmessage
|
||||||
|
auto_restart=n
|
||||||
|
```
|
||||||
|
*srvinstall.bat*
|
||||||
|
```Batchfile
|
||||||
|
srvstart install GoodByeDPI -c %CD%\goodbyedpi.ini
|
||||||
|
```
|
||||||
|
*srvremove.bat*
|
||||||
|
```Batchfile
|
||||||
|
srvstart remove GoodByeDPI
|
||||||
|
```
|
||||||
|
Run these batch files as Administrator to install/remove service.
|
||||||
|
Open Windows Services panel to run service or make it start automaticaly.
|
||||||
|
|
||||||
# Similar projects
|
# Similar projects
|
||||||
|
|
||||||
[zapret](https://github.com/bol-van/zapret) by @bol-van (for Linux).
|
[zapret](https://github.com/bol-van/zapret) by @bol-van (for Linux).
|
||||||
|
|||||||
106
goodbyedpi.c
106
goodbyedpi.c
@@ -21,13 +21,30 @@
|
|||||||
#define IPV4_TOTALLEN_OFFSET 2
|
#define IPV4_TOTALLEN_OFFSET 2
|
||||||
#define TCP_WINDOWSIZE_OFFSET 14
|
#define TCP_WINDOWSIZE_OFFSET 14
|
||||||
|
|
||||||
|
#define DIVERT_NO_LOCALNETS_DST "(" \
|
||||||
|
"(ip.DstAddr < 127.0.0.1 or ip.DstAddr > 127.255.255.255) and " \
|
||||||
|
"(ip.DstAddr < 10.0.0.0 or ip.DstAddr > 10.255.255.255) and " \
|
||||||
|
"(ip.DstAddr < 192.168.0.0 or ip.DstAddr > 192.168.255.255) and " \
|
||||||
|
"(ip.DstAddr < 172.16.0.0 or ip.DstAddr > 172.31.255.255) and " \
|
||||||
|
"(ip.DstAddr < 169.254.0.0 or ip.DstAddr > 169.254.255.255)" \
|
||||||
|
")"
|
||||||
|
#define DIVERT_NO_LOCALNETS_SRC "(" \
|
||||||
|
"(ip.SrcAddr < 127.0.0.1 or ip.SrcAddr > 127.255.255.255) and " \
|
||||||
|
"(ip.SrcAddr < 10.0.0.0 or ip.SrcAddr > 10.255.255.255) and " \
|
||||||
|
"(ip.SrcAddr < 192.168.0.0 or ip.SrcAddr > 192.168.255.255) and " \
|
||||||
|
"(ip.SrcAddr < 172.16.0.0 or ip.SrcAddr > 172.31.255.255) and " \
|
||||||
|
"(ip.SrcAddr < 169.254.0.0 or ip.SrcAddr > 169.254.255.255)" \
|
||||||
|
")"
|
||||||
|
|
||||||
static HANDLE filters[MAX_FILTERS];
|
static HANDLE filters[MAX_FILTERS];
|
||||||
static int filter_num = 0;
|
static int filter_num = 0;
|
||||||
static const char *http10_redirect_302 = "HTTP/1.0 302 ";
|
static const char *http10_redirect_302 = "HTTP/1.0 302 ";
|
||||||
static const char *http11_redirect_302 = "HTTP/1.1 302 ";
|
static const char *http11_redirect_302 = "HTTP/1.1 302 ";
|
||||||
static const char *http_host_find = "\r\nHost: ";
|
static const char *http_host_find = "\r\nHost: ";
|
||||||
static const char *http_host_replace = "\r\nhoSt: ";
|
static const char *http_host_replace = "\r\nhoSt: ";
|
||||||
|
static const char *http_useragent_find = "\r\nUser-Agent: ";
|
||||||
static const char *location_http = "\r\nLocation: http://";
|
static const char *location_http = "\r\nLocation: http://";
|
||||||
|
static const char *connection_close = "\r\nConnection: close";
|
||||||
static const char *http_methods[] = {
|
static const char *http_methods[] = {
|
||||||
"GET ",
|
"GET ",
|
||||||
"HEAD ",
|
"HEAD ",
|
||||||
@@ -60,9 +77,15 @@ static char* dumb_memmem(const char* haystack, int hlen, const char* needle, int
|
|||||||
}
|
}
|
||||||
|
|
||||||
static HANDLE init(char *filter, UINT64 flags) {
|
static HANDLE init(char *filter, UINT64 flags) {
|
||||||
|
LPTSTR errormessage = NULL;
|
||||||
filter = WinDivertOpen(filter, WINDIVERT_LAYER_NETWORK, 0, flags);
|
filter = WinDivertOpen(filter, WINDIVERT_LAYER_NETWORK, 0, flags);
|
||||||
if (filter != INVALID_HANDLE_VALUE)
|
if (filter != INVALID_HANDLE_VALUE)
|
||||||
return filter;
|
return filter;
|
||||||
|
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
|
||||||
|
FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||||
|
NULL, GetLastError(), MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT),
|
||||||
|
(LPTSTR)&errormessage, 0, NULL);
|
||||||
|
printf("%s", errormessage);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,8 +113,9 @@ static int is_passivedpi_redirect(const char *pktdata, int pktlen) {
|
|||||||
if (memcmp(pktdata, http11_redirect_302, strlen(http11_redirect_302)) == 0 ||
|
if (memcmp(pktdata, http11_redirect_302, strlen(http11_redirect_302)) == 0 ||
|
||||||
memcmp(pktdata, http10_redirect_302, strlen(http10_redirect_302)) == 0)
|
memcmp(pktdata, http10_redirect_302, strlen(http10_redirect_302)) == 0)
|
||||||
{
|
{
|
||||||
/* Then check if this is a redirect to new http site */
|
/* Then check if this is a redirect to new http site with Connection: close */
|
||||||
if (dumb_memmem(pktdata, pktlen, location_http, strlen(location_http))) {
|
if (dumb_memmem(pktdata, pktlen, location_http, strlen(location_http)) &&
|
||||||
|
dumb_memmem(pktdata, pktlen, connection_close, strlen(connection_close))) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -104,6 +128,12 @@ static PVOID find_host_header(const char *pktdata, int pktlen) {
|
|||||||
http_host_find, strlen(http_host_find));
|
http_host_find, strlen(http_host_find));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Finds User-Agent header with \r\n before it */
|
||||||
|
static PVOID find_useragent_header(const char *pktdata, int pktlen) {
|
||||||
|
return dumb_memmem(pktdata, pktlen,
|
||||||
|
http_useragent_find, strlen(http_useragent_find));
|
||||||
|
}
|
||||||
|
|
||||||
static void change_window_size(const char *pkt, int size) {
|
static void change_window_size(const char *pkt, int size) {
|
||||||
*(uint16_t*)(pkt + IPV4_HDR_LEN + TCP_WINDOWSIZE_OFFSET) = htons(size);
|
*(uint16_t*)(pkt + IPV4_HDR_LEN + TCP_WINDOWSIZE_OFFSET) = htons(size);
|
||||||
}
|
}
|
||||||
@@ -138,8 +168,8 @@ int main(int argc, char *argv[]) {
|
|||||||
do_host_removespace = 0, do_additional_space = 0;
|
do_host_removespace = 0, do_additional_space = 0;
|
||||||
int http_fragment_size = 2;
|
int http_fragment_size = 2;
|
||||||
int https_fragment_size = 2;
|
int https_fragment_size = 2;
|
||||||
char *data_addr, *data_addr_rn, *host_addr, *method_addr;
|
char *data_addr, *data_addr_rn, *host_addr, *useragent_addr, *method_addr;
|
||||||
int host_len, fromhost_uptoend_len;
|
int data_len, host_len;
|
||||||
|
|
||||||
printf("GoodbyeDPI: Passive DPI blocker and Active DPI circumvention utility\n");
|
printf("GoodbyeDPI: Passive DPI blocker and Active DPI circumvention utility\n");
|
||||||
|
|
||||||
@@ -223,20 +253,29 @@ int main(int argc, char *argv[]) {
|
|||||||
filter_num = 0;
|
filter_num = 0;
|
||||||
|
|
||||||
if (do_passivedpi) {
|
if (do_passivedpi) {
|
||||||
/* Filter for inbound RST packets with ID = 0 or 1 */
|
/* IPv4 filter for inbound RST packets with ID = 0 or 1 */
|
||||||
filters[filter_num] = init("inbound and (ip.Id == 0x0001 or ip.Id == 0x0000) and "
|
filters[filter_num] = init(
|
||||||
"(tcp.SrcPort == 443 or tcp.SrcPort == 80) and tcp.Rst",
|
"inbound and ip and tcp and "
|
||||||
|
"(ip.Id == 0x0001 or ip.Id == 0x0000) and "
|
||||||
|
"(tcp.SrcPort == 443 or tcp.SrcPort == 80) and tcp.Rst and "
|
||||||
|
DIVERT_NO_LOCALNETS_SRC,
|
||||||
WINDIVERT_FLAG_DROP);
|
WINDIVERT_FLAG_DROP);
|
||||||
filter_num++;
|
filter_num++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Filter for inbound HTTP redirection packets and
|
* IPv4 filter for inbound HTTP redirection packets and
|
||||||
* active DPI circumvention
|
* active DPI circumvention
|
||||||
*/
|
*/
|
||||||
filters[filter_num] = init("(inbound and (ip.Id == 0x0001 or ip.Id == 0x0000) and tcp.SrcPort == 80 and tcp.Ack) "
|
filters[filter_num] = init("ip and tcp and "
|
||||||
"or (inbound and (tcp.SrcPort == 80 or tcp.SrcPort == 443) and tcp.Ack and tcp.Syn) "
|
"(inbound and (("
|
||||||
"or (outbound and (tcp.DstPort == 80 or tcp.DstPort == 443) and tcp.Ack)",
|
"((ip.Id == 0x0001 or ip.Id == 0x0000) and tcp.SrcPort == 80 and tcp.Ack) or "
|
||||||
|
"((tcp.SrcPort == 80 or tcp.SrcPort == 443) and tcp.Ack and tcp.Syn)"
|
||||||
|
") and " DIVERT_NO_LOCALNETS_SRC ") or "
|
||||||
|
"(outbound and "
|
||||||
|
"(tcp.DstPort == 80 or tcp.DstPort == 443) and tcp.Ack and "
|
||||||
|
DIVERT_NO_LOCALNETS_DST ")"
|
||||||
|
")",
|
||||||
0);
|
0);
|
||||||
|
|
||||||
w_filter = filters[filter_num];
|
w_filter = filters[filter_num];
|
||||||
@@ -274,6 +313,7 @@ int main(int argc, char *argv[]) {
|
|||||||
/* Handle OUTBOUND packet, search for Host header */
|
/* Handle OUTBOUND packet, search for Host header */
|
||||||
else if (addr.Direction == WINDIVERT_DIRECTION_OUTBOUND &&
|
else if (addr.Direction == WINDIVERT_DIRECTION_OUTBOUND &&
|
||||||
packet_dataLen > 16 && ppTcpHdr->DstPort == htons(80) &&
|
packet_dataLen > 16 && ppTcpHdr->DstPort == htons(80) &&
|
||||||
|
find_http_method_end(packet_data) &&
|
||||||
(do_host || do_host_removespace)) {
|
(do_host || do_host_removespace)) {
|
||||||
|
|
||||||
data_addr = find_host_header(packet_data, packet_dataLen);
|
data_addr = find_host_header(packet_data, packet_dataLen);
|
||||||
@@ -297,24 +337,44 @@ int main(int argc, char *argv[]) {
|
|||||||
else if (do_host_removespace) {
|
else if (do_host_removespace) {
|
||||||
host_addr = data_addr + strlen(http_host_find);
|
host_addr = data_addr + strlen(http_host_find);
|
||||||
|
|
||||||
fromhost_uptoend_len = packet_dataLen - ((PVOID)host_addr - packet_data);
|
|
||||||
data_addr_rn = dumb_memmem(host_addr,
|
data_addr_rn = dumb_memmem(host_addr,
|
||||||
fromhost_uptoend_len,
|
packet_dataLen - ((PVOID)host_addr - packet_data),
|
||||||
"\r\n", 2);
|
"\r\n", 2);
|
||||||
if (data_addr_rn) {
|
if (data_addr_rn) {
|
||||||
|
/* We move Host header value by one byte to the left and then
|
||||||
|
* "insert" stolen space to the end of User-Agent value because
|
||||||
|
* some web servers are not tolerant to additional space in the
|
||||||
|
* end of Host header.
|
||||||
|
*
|
||||||
|
* Nothing is done if User-Agent header is missing.
|
||||||
|
*/
|
||||||
host_len = data_addr_rn - host_addr;
|
host_len = data_addr_rn - host_addr;
|
||||||
if (host_len <= 64) {
|
useragent_addr = find_useragent_header(packet_data, packet_dataLen);
|
||||||
/* Move memory left by 1 byte and reduce packet size for 1 byte */
|
if (host_len <= 253 && useragent_addr && useragent_addr > host_addr) {
|
||||||
memmove(host_addr - 1, host_addr, fromhost_uptoend_len);
|
/* Performing action only if User-Agent header goes after Host */
|
||||||
/* Reduce "Total Length" in IP header by 1 byte */
|
|
||||||
*(uint16_t*)(packet + IPV4_TOTALLEN_OFFSET) = ntohs(
|
useragent_addr += strlen(http_useragent_find);
|
||||||
htons(*(uint16_t*)(packet + IPV4_TOTALLEN_OFFSET)) - 1);
|
/* useragent_addr is in the beginning of User-Agent value */
|
||||||
/* Reduce packetLen by 1 byte */
|
|
||||||
packetLen--;
|
data_len = packet_dataLen - ((PVOID)useragent_addr - packet_data);
|
||||||
|
data_addr_rn = dumb_memmem(useragent_addr,
|
||||||
|
data_len, "\r\n", 2);
|
||||||
|
/* data_addr_rn is in the end of User-Agent value */
|
||||||
|
|
||||||
|
if (data_addr_rn) {
|
||||||
|
data_len = (PVOID)data_addr_rn - (PVOID)host_addr;
|
||||||
|
|
||||||
|
/* Move one byte to the left from "Host:"
|
||||||
|
* to the end of User-Agen
|
||||||
|
*/
|
||||||
|
memmove(host_addr - 1, host_addr, data_len);
|
||||||
|
/* Put space in the end of User-Agent header */
|
||||||
|
*(char*)(data_addr_rn - 1) = ' ';
|
||||||
//printf("Replaced Host header!\n");
|
//printf("Replaced Host header!\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
WinDivertHelperCalcChecksums(packet, packetLen, 0);
|
WinDivertHelperCalcChecksums(packet, packetLen, 0);
|
||||||
}
|
}
|
||||||
@@ -327,11 +387,11 @@ int main(int argc, char *argv[]) {
|
|||||||
if (addr.Direction == WINDIVERT_DIRECTION_INBOUND &&
|
if (addr.Direction == WINDIVERT_DIRECTION_INBOUND &&
|
||||||
ppTcpHdr->Syn == 1) {
|
ppTcpHdr->Syn == 1) {
|
||||||
//printf("Changing Window Size!\n");
|
//printf("Changing Window Size!\n");
|
||||||
if (do_fragment_http && ppTcpHdr->DstPort == htons(80)) {
|
if (do_fragment_http && ppTcpHdr->SrcPort == htons(80)) {
|
||||||
change_window_size(packet, http_fragment_size);
|
change_window_size(packet, http_fragment_size);
|
||||||
WinDivertHelperCalcChecksums(packet, packetLen, 0);
|
WinDivertHelperCalcChecksums(packet, packetLen, 0);
|
||||||
}
|
}
|
||||||
else if (do_fragment_https && ppTcpHdr->DstPort != htons(80)) {
|
else if (do_fragment_https && ppTcpHdr->SrcPort != htons(80)) {
|
||||||
change_window_size(packet, https_fragment_size);
|
change_window_size(packet, https_fragment_size);
|
||||||
WinDivertHelperCalcChecksums(packet, packetLen, 0);
|
WinDivertHelperCalcChecksums(packet, packetLen, 0);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user