From 32ea58c36af8f03d215838a3d32871c7a1701414 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Thu, 27 Feb 2020 16:41:52 +0100 Subject: [PATCH] Le patchage est total --- src/donar.c | 5 ++++- src/donar_client.c | 5 +++-- src/donar_client.h | 1 + src/donar_init.c | 2 ++ src/donar_init.h | 2 +- src/donar_server.c | 7 ++++--- src/packet.h | 4 +++- src/stopwatch.c | 4 ++-- src/test.c | 7 +++++++ src/tor_ctl.c | 4 ++-- src/tor_ctl.h | 1 + 11 files changed, 30 insertions(+), 12 deletions(-) diff --git a/src/donar.c b/src/donar.c index 861f599..cbe4fb0 100644 --- a/src/donar.c +++ b/src/donar.c @@ -16,7 +16,7 @@ int main(int argc, char** argv) { struct donar_params dp = {0}; donar_init_params (&dp); - while ((dp.opt = getopt(argc, argv, "nvcse:r:o:a:bl:d:f:i:p:")) != -1) { + while ((dp.opt = getopt(argc, argv, "nvcse:r:o:a:bl:d:f:i:p:t:")) != -1) { switch(dp.opt) { case 'n': dp.tof |= TOR_ONION_FLAG_NON_ANONYMOUS; @@ -64,6 +64,9 @@ int main(int argc, char** argv) { case 'f': dp.capture_file = strdup(optarg); break; + case 't': + sscanf(optarg, "%[^!]!%[^!]", dp.tor_ip, dp.my_ip_for_tor); + break; default: goto in_error; } diff --git a/src/donar_client.c b/src/donar_client.c index 44cc83b..e70fe54 100644 --- a/src/donar_client.c +++ b/src/donar_client.c @@ -14,7 +14,7 @@ void init_socks5_client(struct donar_client_ctx* app_ctx, int pos) { sprintf(target_host, "%s.onion", app_ctx->tos.keys[0].pub); app_ctx->ports[pos] = 7500 + pos; - socks5_create_dns_client (&app_ctx->evts, "127.0.0.1", "9050", target_host, app_ctx->ports[pos]); + socks5_create_dns_client (&app_ctx->evts, app_ctx->tor_ip, "9050", target_host, app_ctx->ports[pos]); } int on_socks5_success(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo) { @@ -135,6 +135,7 @@ void donar_client(struct donar_client_ctx* ctx, struct donar_params* dp) { .capture_file = dp->capture_file, .sr = donar_client_stream_repair }; + ctx->tor_ip = dp->tor_ip; evt_core_init (&(ctx->evts), dp->verbose); @@ -156,7 +157,7 @@ void donar_client(struct donar_client_ctx* ctx, struct donar_params* dp) { for (int64_t i = 0; i < dp->links; i++) { int64_t to_wait_sec = i * 3; - fprintf(stdout, "[%s][donar-client] Triggering socks5 in %ld seconds for port %d\n", current_human_datetime (), to_wait_sec, i+7500); + fprintf(stdout, "[%s][donar-client] Triggering socks5 in %ld seconds for port %ld\n", current_human_datetime (), to_wait_sec, i+7500); set_timeout(&ctx->evts, 1000 * to_wait_sec, (void*) i, reinit_socks5); } printf("--- TCP Clients Connected\n"); diff --git a/src/donar_client.h b/src/donar_client.h index 41fdfc5..f59be5c 100644 --- a/src/donar_client.h +++ b/src/donar_client.h @@ -13,6 +13,7 @@ struct donar_client_ctx { struct tor_os_str tos; struct evt_core_ctx evts; + char *tor_ip; uint16_t ports[CLIENT_PORT_SIZE]; struct { int fd; diff --git a/src/donar_init.c b/src/donar_init.c index 7e5e78e..69b1d9b 100644 --- a/src/donar_init.c +++ b/src/donar_init.c @@ -158,6 +158,8 @@ void donar_init_params(struct donar_params* dp) { dp->links = 8; dp->fresh_data = 1; dp->redundant_data = 0; + strcpy(dp->tor_ip, "127.0.0.1"); + strcpy(dp->my_ip_for_tor, "127.13.3.7"); dp->remote_ports = g_ptr_array_new_with_free_func (free_port); dp->exposed_ports = g_ptr_array_new_with_free_func (free_port); } diff --git a/src/donar_init.h b/src/donar_init.h index 8b9c781..87aa602 100644 --- a/src/donar_init.h +++ b/src/donar_init.h @@ -11,7 +11,7 @@ struct donar_params { int opt, is_server, is_client, is_waiting_bootstrap, errored, verbose, links, fresh_data, redundant_data; - char *bound_ip, *port, *onion_file, *algo, *capture_file, *algo_specific_params; + char *bound_ip, *port, *onion_file, *algo, *capture_file, *algo_specific_params, tor_ip[16], my_ip_for_tor[16]; GPtrArray *remote_ports, *exposed_ports; enum TOR_ONION_FLAGS tof; }; diff --git a/src/donar_server.c b/src/donar_server.c index def1490..f29ffc3 100644 --- a/src/donar_server.c +++ b/src/donar_server.c @@ -1,11 +1,11 @@ #include "donar_server.h" -void create_onion_services(struct tor_os_str* tos, struct tor_ctl* tctl, uint16_t* ports, int ports_count, enum TOR_ONION_FLAGS tof) { +void create_onion_services(struct tor_os_str* tos, struct tor_ctl* tctl, char* tor_ip, uint16_t* ports, int ports_count, enum TOR_ONION_FLAGS tof) { tor_os_create (tos, "onion_services.pub", "onion_services.txt", 1); tor_os_read (tos); int err = 0; - err = tor_ctl_connect (tctl, "127.0.0.1", "9051"); + err = tor_ctl_connect (tctl, tor_ip, "9051"); if (err < 0) { fprintf(stderr, "Unable to open Tor Socket\n"); exit(EXIT_FAILURE); @@ -123,7 +123,8 @@ void donar_server(struct donar_server_ctx* ctx, struct donar_params* dp) { init_tcp_servers(ctx, dp->links); printf("--- TCP servers are listening\n"); - create_onion_services (&(ctx->tos), &(ctx->tctl), ctx->ports, dp->links, dp->tof); + ctx->tctl.os_endpoint = dp->my_ip_for_tor; + create_onion_services (&(ctx->tos), &(ctx->tctl), dp->tor_ip, ctx->ports, dp->links, dp->tof); ugly_global_tctl = &(ctx->tctl); /*struct donar_server_os_republish_params dsorp = { .dctx = ctx, dp = dp}; init_timer(&(ctx->evts)); diff --git a/src/packet.h b/src/packet.h index cc0a342..d622ab0 100644 --- a/src/packet.h +++ b/src/packet.h @@ -12,6 +12,8 @@ #include "evt_core.h" #include "url.h" +#define UDP_MTU 65535 + /* * man 7 udp about receive operation on UDP sockets: * @@ -83,7 +85,7 @@ struct buffer_packet { uint16_t aread; uint16_t awrite; struct timespec seen; - char ip[6000]; + char ip[UDP_MTU]; }; struct udp_target { diff --git a/src/stopwatch.c b/src/stopwatch.c index aecd698..1d409f9 100644 --- a/src/stopwatch.c +++ b/src/stopwatch.c @@ -17,7 +17,7 @@ void timing_fx_start(struct timing_fx* tfx, ...) { va_end(args); } - if (clock_gettime(CLOCK_MONOTONIC, &tfx->start) == -1) { + if (clock_gettime(CLOCK_MONOTONIC_RAW, &tfx->start) == -1) { perror("clock_gettime"); exit(EXIT_FAILURE); } @@ -30,7 +30,7 @@ double timing_fx_stop(struct timing_fx* tfx, ...) { if (!(tfx->config & TIMING_ACTIVATED)) return 0.; - if (clock_gettime(CLOCK_MONOTONIC, &stop) == -1) { + if (clock_gettime(CLOCK_MONOTONIC_RAW, &stop) == -1) { perror("clock_gettime"); exit(EXIT_FAILURE); } diff --git a/src/test.c b/src/test.c index 8490cf1..15d48a6 100644 --- a/src/test.c +++ b/src/test.c @@ -3,9 +3,16 @@ #include #include #include "proxy.h" +#include "stopwatch.h" +#include int main(int argc, char** argv) { setvbuf(stdout, NULL, _IONBF, 0); printf("~ test ~\n"); + timing_fx_init (&static_tfx, TIMING_ACTIVATED|TIMING_DISPLAY_END, "", "info=%s"); + timing_fx_start (&static_tfx); + sleep(1); + timing_fx_stop(&static_tfx, "sleep(1)"); + } diff --git a/src/tor_ctl.c b/src/tor_ctl.c index 9bb571c..5dfef83 100644 --- a/src/tor_ctl.c +++ b/src/tor_ctl.c @@ -87,7 +87,7 @@ int tor_ctl_add_onion(struct tor_ctl* ctx, struct tor_os_str* tos, uint16_t* por for (int i = 0; i < tos->filled; i++) { fprintf(ctx->wsock, "add_onion %s ", tos->keys[i].priv); for (int j = 0; j < port_per_os; j++) { - fprintf(ctx->wsock, "Port=%d,127.13.3.7:%d ", port[i*port_per_os+j], port[i*port_per_os+j]); + fprintf(ctx->wsock, "Port=%d,%s:%d ", port[i*port_per_os+j], ctx->os_endpoint, port[i*port_per_os+j]); } if (flags == TOR_ONION_FLAG_NONE) fprintf(ctx->wsock, "\n"); else { @@ -110,7 +110,7 @@ int tor_ctl_add_onion(struct tor_ctl* ctx, struct tor_os_str* tos, uint16_t* por for (int i = tos->filled; i < tos->size; i++) { fprintf(ctx->wsock, "add_onion NEW:ED25519-V3 "); for (int j = 0; j < port_per_os; j++) { - fprintf(ctx->wsock, "Port=%d,127.13.3.7:%d ", port[i*port_per_os+j], port[i*port_per_os+j]); + fprintf(ctx->wsock, "Port=%d,%s:%d ", port[i*port_per_os+j], ctx->os_endpoint, port[i*port_per_os+j]); } if (flags == TOR_ONION_FLAG_NONE) fprintf(ctx->wsock, "\n"); else { diff --git a/src/tor_ctl.h b/src/tor_ctl.h index 60d7a2d..95e7e48 100644 --- a/src/tor_ctl.h +++ b/src/tor_ctl.h @@ -11,6 +11,7 @@ * https://ycpcs.github.io/cs365-spring2019/lectures/lecture15.html */ struct tor_ctl { + char* os_endpoint; FILE* rsock; FILE* wsock; };