Skip to content

Commit e25d743

Browse files
committed
Better Auto TTL adjusting algorithm which honors short distance
Say you set --auto-ttl to 4. If the TTL distance to the destination host is too short, say 6, auto-ttl would decrease it by 4 and send a fake packet with TTL 2, which is too low for the packet to travel via DPI system. But if you set --auto-ttl to a lower value such as 2, that may introduce issues over long lines where outgoing-path TTL and incoming-path TTL may have difference more than 2 hops due to higher chance of assymetric routing along the path. To solve this issue, this commit introduce auto-ttl range of two values. If the incoming TTL distance is more than autottl2, it is subtracted by autottl2 value. If the distance is less than autottl2, the distance value is used as a normalized weigth of [autottl1; autottl2] scale. The simplified formula is as follows: 128 > extracted_ttl > 98: // Server is running Windows nhops = 128 - extracted_ttl 64 > extracted_ttl > 34: // Server is running Linux/FreeBSD/other nhops = 64 - extracted_ttl if (nhops - autottl2 < autottl2) ttl_of_fake_packet = nhops - autottl1 - trunc((autottl2 - autottl1) * ((float)nhops/10)); else ttl_of_fake_packet = nhops - autottl2
1 parent c60dbf7 commit e25d743

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

src/goodbyedpi.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ WINSOCK_API_LINKAGE INT WSAAPI inet_pton(INT Family, LPCSTR pStringBuf, PVOID pA
104104
ppTcpHdr->SrcPort, ppTcpHdr->DstPort, \
105105
&tcp_conn_info, 1))) \
106106
{ \
107-
ttl_of_fake_packet = tcp_get_auto_ttl(tcp_conn_info.ttl, do_auto_ttl); \
107+
ttl_of_fake_packet = tcp_get_auto_ttl(tcp_conn_info.ttl, 1, do_auto_ttl, 3); \
108108
if (do_tcp_verb) { \
109109
printf("Connection TTL = %d, Fake TTL = %d\n", tcp_conn_info.ttl, ttl_of_fake_packet); \
110110
} \

src/ttltrack.c

+16-10
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <windows.h>
99
#include <time.h>
1010
#include <stdio.h>
11+
#include <math.h>
1112
#include "goodbyedpi.h"
1213
#include "ttltrack.h"
1314
#include "utils/uthash.h"
@@ -218,23 +219,28 @@ int tcp_handle_outgoing(uint32_t srcip[4], uint32_t dstip[4],
218219
return FALSE;
219220
}
220221

221-
int tcp_get_auto_ttl(const uint8_t ttl, const uint8_t decrease_for) {
222+
int tcp_get_auto_ttl(const uint8_t ttl, const uint8_t autottl1,
223+
const uint8_t autottl2, const uint8_t minhops) {
224+
uint8_t nhops = 0;
222225
uint8_t ttl_of_fake_packet = 0;
223226

224227
if (ttl > 98 && ttl < 128) {
225-
/* Safekeeping */
226-
if (128 - ttl > decrease_for + 1) {
227-
ttl_of_fake_packet = 128 - ttl - decrease_for;
228-
}
228+
nhops = 128 - ttl;
229229
}
230230
else if (ttl > 34 && ttl < 64) {
231-
/* Safekeeping */
232-
if (64 - ttl > decrease_for + 1) {
233-
ttl_of_fake_packet = 64 - ttl - decrease_for;
234-
}
231+
nhops = 64 - ttl;
235232
}
236233
else {
237-
ttl_of_fake_packet = 0;
234+
return 0;
235+
}
236+
237+
if (nhops <= autottl1 || nhops < minhops) {
238+
return 0;
239+
}
240+
241+
ttl_of_fake_packet = nhops - autottl2;
242+
if (ttl_of_fake_packet < autottl2 && nhops <= 9) {
243+
ttl_of_fake_packet = nhops - autottl1 - trunc((autottl2 - autottl1) * ((float)nhops/10));
238244
}
239245

240246
return ttl_of_fake_packet;

src/ttltrack.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,6 @@ int tcp_handle_outgoing(uint32_t srcip[4], uint32_t dstip[4],
2121
tcp_conntrack_info_t *conn_info,
2222
uint8_t is_ipv6);
2323

24-
int tcp_get_auto_ttl(uint8_t ttl, uint8_t decrease_for);
24+
int tcp_get_auto_ttl(const uint8_t ttl, const uint8_t autottl1,
25+
const uint8_t autottl2, const uint8_t minhops);
2526
#endif

0 commit comments

Comments
 (0)