diff --git a/src/goodbyedpi.c b/src/goodbyedpi.c index e699594..aeb3e09 100644 --- a/src/goodbyedpi.c +++ b/src/goodbyedpi.c @@ -104,7 +104,7 @@ WINSOCK_API_LINKAGE INT WSAAPI inet_pton(INT Family, LPCSTR pStringBuf, PVOID pA ppTcpHdr->SrcPort, ppTcpHdr->DstPort, \ &tcp_conn_info, 1))) \ { \ - ttl_of_fake_packet = tcp_get_auto_ttl(tcp_conn_info.ttl, do_auto_ttl); \ + ttl_of_fake_packet = tcp_get_auto_ttl(tcp_conn_info.ttl, 1, do_auto_ttl, 3); \ if (do_tcp_verb) { \ printf("Connection TTL = %d, Fake TTL = %d\n", tcp_conn_info.ttl, ttl_of_fake_packet); \ } \ diff --git a/src/ttltrack.c b/src/ttltrack.c index ef12b5d..ba1a931 100644 --- a/src/ttltrack.c +++ b/src/ttltrack.c @@ -8,6 +8,7 @@ #include #include #include +#include #include "goodbyedpi.h" #include "ttltrack.h" #include "utils/uthash.h" @@ -218,23 +219,28 @@ int tcp_handle_outgoing(uint32_t srcip[4], uint32_t dstip[4], return FALSE; } -int tcp_get_auto_ttl(const uint8_t ttl, const uint8_t decrease_for) { +int tcp_get_auto_ttl(const uint8_t ttl, const uint8_t autottl1, + const uint8_t autottl2, const uint8_t minhops) { + uint8_t nhops = 0; uint8_t ttl_of_fake_packet = 0; if (ttl > 98 && ttl < 128) { - /* Safekeeping */ - if (128 - ttl > decrease_for + 1) { - ttl_of_fake_packet = 128 - ttl - decrease_for; - } + nhops = 128 - ttl; } else if (ttl > 34 && ttl < 64) { - /* Safekeeping */ - if (64 - ttl > decrease_for + 1) { - ttl_of_fake_packet = 64 - ttl - decrease_for; - } + nhops = 64 - ttl; } else { - ttl_of_fake_packet = 0; + return 0; + } + + if (nhops <= autottl1 || nhops < minhops) { + return 0; + } + + ttl_of_fake_packet = nhops - autottl2; + if (ttl_of_fake_packet < autottl2 && nhops <= 9) { + ttl_of_fake_packet = nhops - autottl1 - trunc((autottl2 - autottl1) * ((float)nhops/10)); } return ttl_of_fake_packet; diff --git a/src/ttltrack.h b/src/ttltrack.h index 187a535..0563298 100644 --- a/src/ttltrack.h +++ b/src/ttltrack.h @@ -21,5 +21,6 @@ int tcp_handle_outgoing(uint32_t srcip[4], uint32_t dstip[4], tcp_conntrack_info_t *conn_info, uint8_t is_ipv6); -int tcp_get_auto_ttl(uint8_t ttl, uint8_t decrease_for); +int tcp_get_auto_ttl(const uint8_t ttl, const uint8_t autottl1, + const uint8_t autottl2, const uint8_t minhops); #endif