mirror of
https://github.com/ValdikSS/GoodbyeDPI.git
synced 2025-12-17 21:04:36 +03:00
Merge branch 'badseq_for_master' into master
This commit is contained in:
115
src/goodbyedpi.c
115
src/goodbyedpi.c
@@ -16,6 +16,7 @@
|
||||
#include "utils/repl_str.h"
|
||||
#include "service.h"
|
||||
#include "dnsredir.h"
|
||||
#include "ttltrack.h"
|
||||
#include "blackwhitelist.h"
|
||||
#include "fakepackets.h"
|
||||
|
||||
@@ -94,6 +95,22 @@ WINSOCK_API_LINKAGE INT WSAAPI inet_pton(INT Family, LPCSTR pStringBuf, PVOID pA
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define TCP_HANDLE_OUTGOING_ADJUST_TTL() do { \
|
||||
if ((packet_v4 && tcp_handle_outgoing(&ppIpHdr->SrcAddr, &ppIpHdr->DstAddr, \
|
||||
ppTcpHdr->SrcPort, ppTcpHdr->DstPort, \
|
||||
&tcp_conn_info, 0)) \
|
||||
|| \
|
||||
(packet_v6 && tcp_handle_outgoing(ppIpV6Hdr->SrcAddr, ppIpV6Hdr->DstAddr, \
|
||||
ppTcpHdr->SrcPort, ppTcpHdr->DstPort, \
|
||||
&tcp_conn_info, 1))) \
|
||||
{ \
|
||||
ttl_of_fake_packet = tcp_get_auto_ttl(tcp_conn_info.ttl, do_auto_ttl); \
|
||||
if (do_tcp_verb) { \
|
||||
printf("Connection TTL = %d, Fake TTL = %d\n", tcp_conn_info.ttl, ttl_of_fake_packet); \
|
||||
} \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
static int running_from_service = 0;
|
||||
static HANDLE filters[MAX_FILTERS];
|
||||
static int filter_num = 0;
|
||||
@@ -124,7 +141,9 @@ static struct option long_options[] = {
|
||||
{"blacklist", required_argument, 0, 'b' },
|
||||
{"ip-id", required_argument, 0, 'i' },
|
||||
{"set-ttl", required_argument, 0, '$' },
|
||||
{"auto-ttl", optional_argument, 0, '+' },
|
||||
{"wrong-chksum",no_argument, 0, '%' },
|
||||
{"wrong-seq", no_argument, 0, ')' },
|
||||
{"native-frag", no_argument, 0, '*' },
|
||||
{"reverse-frag",no_argument, 0, '(' },
|
||||
{0, 0, 0, 0 }
|
||||
@@ -487,6 +506,7 @@ int main(int argc, char *argv[]) {
|
||||
PWINDIVERT_TCPHDR ppTcpHdr;
|
||||
PWINDIVERT_UDPHDR ppUdpHdr;
|
||||
conntrack_info_t dns_conn_info;
|
||||
tcp_conntrack_info_t tcp_conn_info;
|
||||
|
||||
int do_passivedpi = 0, do_fragment_http = 0,
|
||||
do_fragment_http_persistent = 0,
|
||||
@@ -496,9 +516,11 @@ int main(int argc, char *argv[]) {
|
||||
do_http_allports = 0,
|
||||
do_host_mixedcase = 0,
|
||||
do_dnsv4_redirect = 0, do_dnsv6_redirect = 0,
|
||||
do_dns_verb = 0, do_blacklist = 0,
|
||||
do_dns_verb = 0, do_tcp_verb = 0, do_blacklist = 0,
|
||||
do_fake_packet = 0,
|
||||
do_auto_ttl = 0,
|
||||
do_wrong_chksum = 0,
|
||||
do_wrong_seq = 0,
|
||||
do_native_frag = 0, do_reverse_frag = 0;
|
||||
unsigned int http_fragment_size = 0;
|
||||
unsigned int https_fragment_size = 0;
|
||||
@@ -695,6 +717,7 @@ int main(int argc, char *argv[]) {
|
||||
break;
|
||||
case 'v':
|
||||
do_dns_verb = 1;
|
||||
do_tcp_verb = 1;
|
||||
break;
|
||||
case 'b':
|
||||
do_blacklist = 1;
|
||||
@@ -707,10 +730,23 @@ int main(int argc, char *argv[]) {
|
||||
do_fake_packet = 1;
|
||||
ttl_of_fake_packet = atoub(optarg, "Set TTL parameter error!");
|
||||
break;
|
||||
case '+':
|
||||
do_fake_packet = 1;
|
||||
do_auto_ttl = 2;
|
||||
if (optarg) {
|
||||
do_auto_ttl = atoub(optarg, "Set Auto TTL parameter error!");
|
||||
} else if (argv[optind] && argv[optind][0] != '-') {
|
||||
do_auto_ttl = atoub(argv[optind], "Set Auto TTL parameter error!");
|
||||
}
|
||||
break;
|
||||
case '%':
|
||||
do_fake_packet = 1;
|
||||
do_wrong_chksum = 1;
|
||||
break;
|
||||
case ')':
|
||||
do_fake_packet = 1;
|
||||
do_wrong_seq = 1;
|
||||
break;
|
||||
case '*':
|
||||
do_native_frag = 1;
|
||||
do_fragment_http_persistent = 1;
|
||||
@@ -729,27 +765,29 @@ int main(int argc, char *argv[]) {
|
||||
" -s remove space between host header and its value\n"
|
||||
" -a additional space between Method and Request-URI (enables -s, may break sites)\n"
|
||||
" -m mix Host header case (test.com -> tEsT.cOm)\n"
|
||||
" -f [value] set HTTP fragmentation to value\n"
|
||||
" -k [value] enable HTTP persistent (keep-alive) fragmentation and set it to value\n"
|
||||
" -f <value> set HTTP fragmentation to value\n"
|
||||
" -k <value> enable HTTP persistent (keep-alive) fragmentation and set it to value\n"
|
||||
" -n do not wait for first segment ACK when -k is enabled\n"
|
||||
" -e [value] set HTTPS fragmentation to value\n"
|
||||
" -e <value> set HTTPS fragmentation to value\n"
|
||||
" -w try to find and parse HTTP traffic on all processed ports (not only on port 80)\n"
|
||||
" --port [value] additional TCP port to perform fragmentation on (and HTTP tricks with -w)\n"
|
||||
" --ip-id [value] handle additional IP ID (decimal, drop redirects and TCP RSTs with this ID).\n"
|
||||
" --dns-addr [value] redirect UDPv4 DNS requests to the supplied IPv4 address (experimental)\n"
|
||||
" --dns-port [value] redirect UDPv4 DNS requests to the supplied port (53 by default)\n"
|
||||
" --dnsv6-addr [value] redirect UDPv6 DNS requests to the supplied IPv6 address (experimental)\n"
|
||||
" --dnsv6-port [value] redirect UDPv6 DNS requests to the supplied port (53 by default)\n"
|
||||
" --port <value> additional TCP port to perform fragmentation on (and HTTP tricks with -w)\n"
|
||||
" --ip-id <value> handle additional IP ID (decimal, drop redirects and TCP RSTs with this ID).\n"
|
||||
" --dns-addr <value> redirect UDPv4 DNS requests to the supplied IPv4 address (experimental)\n"
|
||||
" --dns-port <value> redirect UDPv4 DNS requests to the supplied port (53 by default)\n"
|
||||
" --dnsv6-addr <value> redirect UDPv6 DNS requests to the supplied IPv6 address (experimental)\n"
|
||||
" --dnsv6-port <value> redirect UDPv6 DNS requests to the supplied port (53 by default)\n"
|
||||
" --dns-verb print verbose DNS redirection messages\n"
|
||||
" --blacklist [txtfile] perform circumvention tricks only to host names and subdomains from\n"
|
||||
" --blacklist <txtfile> perform circumvention tricks only to host names and subdomains from\n"
|
||||
" supplied text file (HTTP Host/TLS SNI).\n"
|
||||
" This option can be supplied multiple times.\n"
|
||||
" --set-ttl [value] activate Fake Request Mode and send it with supplied TTL value.\n"
|
||||
" --set-ttl <value> activate Fake Request Mode and send it with supplied TTL value.\n"
|
||||
" DANGEROUS! May break websites in unexpected ways. Use with care.\n"
|
||||
" Could be combined with --wrong-chksum.\n"
|
||||
" --auto-ttl [decttl] activate Fake Request Mode, automatically detect TTL and decrease\n"
|
||||
" it from standard 64 or 128 by decttl (128/64 - TTL - 2 by default).\n"
|
||||
" --wrong-chksum activate Fake Request Mode and send it with incorrect TCP checksum.\n"
|
||||
" May not work in a VM or with some routers, but is safer than set-ttl.\n"
|
||||
" Could be combined with --set-ttl\n"
|
||||
" --wrong-seq activate Fake Request Mode and send it with TCP SEQ/ACK in the past.\n"
|
||||
" --native-frag fragment (split) the packets by sending them in smaller packets, without\n"
|
||||
" shrinking the Window Size. Works faster (does not slow down the connection)\n"
|
||||
" and better.\n"
|
||||
@@ -776,14 +814,16 @@ int main(int argc, char *argv[]) {
|
||||
"hoSt: %d\nHost no space: %d\nAdditional space: %d\n"
|
||||
"Mix Host: %d\nHTTP AllPorts: %d\nHTTP Persistent Nowait: %d\n"
|
||||
"DNS redirect: %d\nDNSv6 redirect: %d\n"
|
||||
"Fake requests, TTL: %hu\nFake requests, wrong checksum: %d\n",
|
||||
"Fake requests, TTL: %hu (auto: %hu)\nFake requests, wrong checksum: %d\n"
|
||||
"Fake requests, wrong SEQ/ACK: %d\n",
|
||||
do_passivedpi, (do_fragment_http ? http_fragment_size : 0),
|
||||
(do_fragment_http_persistent ? http_fragment_size : 0),
|
||||
(do_fragment_https ? https_fragment_size : 0),
|
||||
do_native_frag, do_reverse_frag,
|
||||
do_host, do_host_removespace, do_additional_space, do_host_mixedcase,
|
||||
do_http_allports, do_fragment_http_persistent_nowait, do_dnsv4_redirect,
|
||||
do_dnsv6_redirect, ttl_of_fake_packet, do_wrong_chksum
|
||||
do_dnsv6_redirect, ttl_of_fake_packet, do_auto_ttl,
|
||||
do_wrong_chksum, do_wrong_seq
|
||||
);
|
||||
|
||||
if (do_fragment_http && http_fragment_size > 2) {
|
||||
@@ -922,8 +962,11 @@ int main(int argc, char *argv[]) {
|
||||
printf("Blocked HTTPS website SNI: %s\n", lsni);
|
||||
#endif
|
||||
if (do_fake_packet) {
|
||||
if (do_auto_ttl) {
|
||||
TCP_HANDLE_OUTGOING_ADJUST_TTL();
|
||||
}
|
||||
send_fake_https_request(w_filter, &addr, packet, packetLen, packet_v6,
|
||||
ttl_of_fake_packet, do_wrong_chksum);
|
||||
ttl_of_fake_packet, do_wrong_chksum, do_wrong_seq);
|
||||
}
|
||||
if (do_native_frag) {
|
||||
// Signal for native fragmentation code handler
|
||||
@@ -963,9 +1006,13 @@ int main(int argc, char *argv[]) {
|
||||
should_recalc_checksum = 1;
|
||||
}
|
||||
|
||||
if (do_fake_packet)
|
||||
if (do_fake_packet) {
|
||||
if (do_auto_ttl) {
|
||||
TCP_HANDLE_OUTGOING_ADJUST_TTL();
|
||||
}
|
||||
send_fake_http_request(w_filter, &addr, packet, packetLen, packet_v6,
|
||||
ttl_of_fake_packet, do_wrong_chksum);
|
||||
ttl_of_fake_packet, do_wrong_chksum, do_wrong_seq);
|
||||
}
|
||||
|
||||
if (do_host_mixedcase) {
|
||||
mix_case(host_addr, host_len);
|
||||
@@ -1078,20 +1125,36 @@ int main(int argc, char *argv[]) {
|
||||
else if (packet_type == ipv4_tcp || packet_type == ipv6_tcp) {
|
||||
/* If we got INBOUND SYN+ACK packet */
|
||||
if (addr.Direction == WINDIVERT_DIRECTION_INBOUND &&
|
||||
ppTcpHdr->Syn == 1 && ppTcpHdr->Ack == 1 &&
|
||||
!do_native_frag) {
|
||||
ppTcpHdr->Syn == 1 && ppTcpHdr->Ack == 1) {
|
||||
//printf("Changing Window Size!\n");
|
||||
/*
|
||||
* Window Size is changed even if do_fragment_http_persistent
|
||||
* is enabled as there could be non-HTTP data on port 80
|
||||
*/
|
||||
if (do_fragment_http && ppTcpHdr->SrcPort == htons(80)) {
|
||||
change_window_size(ppTcpHdr, http_fragment_size);
|
||||
should_recalc_checksum = 1;
|
||||
|
||||
if (do_fake_packet && do_auto_ttl) {
|
||||
if (!((packet_v4 && tcp_handle_incoming(&ppIpHdr->SrcAddr, &ppIpHdr->DstAddr,
|
||||
ppTcpHdr->SrcPort, ppTcpHdr->DstPort,
|
||||
0, ppIpHdr->TTL))
|
||||
||
|
||||
(packet_v6 && tcp_handle_incoming(&ppIpV6Hdr->SrcAddr, &ppIpV6Hdr->DstAddr,
|
||||
ppTcpHdr->SrcPort, ppTcpHdr->DstPort,
|
||||
1, ppIpV6Hdr->HopLimit))))
|
||||
{
|
||||
if (do_tcp_verb)
|
||||
puts("[TCP WARN] Can't add TCP connection record.");
|
||||
}
|
||||
}
|
||||
else if (do_fragment_https && ppTcpHdr->SrcPort != htons(80)) {
|
||||
change_window_size(ppTcpHdr, https_fragment_size);
|
||||
should_recalc_checksum = 1;
|
||||
|
||||
if (!do_native_frag) {
|
||||
if (do_fragment_http && ppTcpHdr->SrcPort == htons(80)) {
|
||||
change_window_size(ppTcpHdr, http_fragment_size);
|
||||
should_recalc_checksum = 1;
|
||||
}
|
||||
else if (do_fragment_https && ppTcpHdr->SrcPort != htons(80)) {
|
||||
change_window_size(ppTcpHdr, https_fragment_size);
|
||||
should_recalc_checksum = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user