From 8f19f65e85cc23f03d68fafa149f36f84e919ecf Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Wed, 4 Sep 2019 16:40:02 +0200 Subject: [PATCH] Add feature to create single hop circuits --- scripts/Makefile | 19 ++++++++++++++++++- scripts/orig-server | 2 +- src/donar.c | 7 +++++-- src/donar_init.h | 2 ++ src/donar_server.c | 6 +++--- src/tor_ctl.c | 11 +++++++++-- src/tor_ctl.h | 7 ++++++- src/tor_echo.c | 20 ++++++++++++++++---- torrc_single_hop | 7 +++++++ 9 files changed, 67 insertions(+), 14 deletions(-) create mode 100644 torrc_single_hop diff --git a/scripts/Makefile b/scripts/Makefile index 88d2b30..c53094e 100644 --- a/scripts/Makefile +++ b/scripts/Makefile @@ -72,4 +72,21 @@ tor_guards_full: tor3 -f /etc/torrc_guard_6, \ tor3 -f /etc/torrc_guard_7, \ tor3 -f /etc/torrc_guard_8, \ - tor3 -f /etc/torrc_simple + tor3 -f /etc/torrc_simple + +tor_relays_small: + ./run-3 \ + 1 . \ + orig-client 600 100 100, \ + orig-client 600 100 100, \ + orig-client 600 100 100 . \ + orig-server, \ + orig-server, \ + orig-server . \ + tor3 -f /etc/torrc_simple, \ + tor2 -f /etc/torrc_simple, \ + tor2 -f /etc/torrc_simple . \ + tor3 -f /etc/torrc_simple, \ + tor2 -f /etc/torrc_simple, \ + tor2 -f /etc/torrc_single_hop + diff --git a/scripts/orig-server b/scripts/orig-server index dd3cbf5..f785c38 100755 --- a/scripts/orig-server +++ b/scripts/orig-server @@ -1,4 +1,4 @@ #!/bin/bash mkdir -p $1/{log,shared} cd $1/shared -torecho > ../log/server-udpecho-stdout.log 2> ../log/server-udpecho-stderr.log +torecho -n > ../log/server-udpecho-stdout.log 2> ../log/server-udpecho-stderr.log diff --git a/src/donar.c b/src/donar.c index 5ebdf0d..058ec8c 100644 --- a/src/donar.c +++ b/src/donar.c @@ -14,8 +14,11 @@ int main(int argc, char** argv) { struct donar_params dp = {0}; donar_init_params (&dp); - while ((dp.opt = getopt(argc, argv, "vcse:r:o:a:bhl:d:f:i:")) != -1) { + while ((dp.opt = getopt(argc, argv, "nvcse:r:o:a:bhl:d:f:i:")) != -1) { switch(dp.opt) { + case 'n': + dp.tof |= TOR_ONION_FLAG_NON_ANONYMOUS; + break; case 'v': dp.verbose++; break; @@ -82,7 +85,7 @@ int main(int argc, char** argv) { in_error: dp.errored = 1; fprintf(stderr, "Usage as client : %s -c -a -o [-h] [-b] [-i ] [-f ] [-l ] [-d ,] [-e ]* [-r ]*\n", argv[0]); - fprintf(stderr, "Usage as server : %s -s -a [-h] [-b] [-i ] [-l ] [-f ] [-d ,] [-e ]* [-r ]*\n\n", argv[0]); + fprintf(stderr, "Usage as server : %s -s -a [-h] [-b] [-n] [-i ] [-l ] [-f ] [-d ,] [-e ]* [-r ]*\n\n", argv[0]); fprintf(stderr, "Passed parameters: client=%d, server=%d, algo=%s, exposed_ports=%d, remote_ports=%d, onion_file=%s, links=%d, duplication=%d,%d\n", dp.is_client, dp.is_server, dp.algo, dp.exposed_ports->len, dp.remote_ports->len, dp.onion_file, dp.links, dp.fresh_data, dp.redundant_data); diff --git a/src/donar_init.h b/src/donar_init.h index a4d8ad6..ac29df2 100644 --- a/src/donar_init.h +++ b/src/donar_init.h @@ -7,11 +7,13 @@ #include "net_tools.h" #include "evt_core.h" #include "packet.h" +#include "tor_ctl.h" struct donar_params { int opt, is_server, is_client, is_waiting_bootstrap, is_healing, errored, verbose, links, fresh_data, redundant_data; char *bound_ip, *port, *onion_file, *algo, *capture_file; GPtrArray *remote_ports, *exposed_ports; + enum TOR_ONION_FLAGS tof; }; void signal_init(struct evt_core_ctx* evts); diff --git a/src/donar_server.c b/src/donar_server.c index 4f6c2b4..eeccc4a 100644 --- a/src/donar_server.c +++ b/src/donar_server.c @@ -1,6 +1,6 @@ #include "donar_server.h" -void create_onion_services(struct tor_os_str* tos, struct tor_ctl* tctl, uint16_t* ports, int ports_count) { +void create_onion_services(struct tor_os_str* tos, struct tor_ctl* tctl, uint16_t* ports, int ports_count, enum TOR_ONION_FLAGS tof) { tor_os_create (tos, "onion_services.pub", "onion_services.txt", ports_count); tor_os_read (tos); @@ -10,7 +10,7 @@ void create_onion_services(struct tor_os_str* tos, struct tor_ctl* tctl, uint16_ fprintf(stderr, "Unable to open Tor Socket\n"); exit(EXIT_FAILURE); } - err = tor_ctl_add_onion (tctl, tos, ports); + err = tor_ctl_add_onion (tctl, tos, ports, tof); if (err != 0) { fprintf(stderr, "Unable to create Onion Services (error: %d)\n", err); exit(EXIT_FAILURE); @@ -73,7 +73,7 @@ void donar_server(struct donar_server_ctx* ctx, struct donar_params* dp) { for (uint16_t i = 0; i < PORT_SIZE ; i++) { ctx->ports[i] = 7500 + i; } - create_onion_services (&(ctx->tos), &(ctx->tctl), ctx->ports, PORT_SIZE); + create_onion_services (&(ctx->tos), &(ctx->tctl), ctx->ports, PORT_SIZE, dp->tof); printf("--- Onion services created\n"); init_tcp_servers(ctx); diff --git a/src/tor_ctl.c b/src/tor_ctl.c index a253370..6c5536e 100644 --- a/src/tor_ctl.c +++ b/src/tor_ctl.c @@ -30,7 +30,7 @@ int tor_ctl_connect(struct tor_ctl* ctx, char* addr, char* service) { return 0; } -int tor_ctl_add_onion(struct tor_ctl* ctx, struct tor_os_str* tos, uint16_t* port) { +int tor_ctl_add_onion(struct tor_ctl* ctx, struct tor_os_str* tos, uint16_t* port, enum TOR_ONION_FLAGS flags) { int err = 0; char buffer1[1024] = {0}; char buffer2[1024] = {0}; @@ -51,7 +51,14 @@ int tor_ctl_add_onion(struct tor_ctl* ctx, struct tor_os_str* tos, uint16_t* por /* Complete by creating new onion services */ for (int i = tos->filled; i < tos->size; i++) { - fprintf(ctx->wsock, "add_onion NEW:ED25519-V3 Port=%d\n", port[i]); + if (flags == TOR_ONION_FLAG_NONE) + fprintf(ctx->wsock, "add_onion NEW:ED25519-V3 Port=%d\n", port[i]); + else { + fprintf(ctx->wsock, "add_onion NEW:ED25519-V3 Port=%d Flags=", port[i]); + if (flags & TOR_ONION_FLAG_NON_ANONYMOUS) + fprintf(ctx->wsock, "NonAnonymous,"); + fprintf(ctx->wsock, "\n"); + } //fprintf(ctx->wsock, "add_onion NEW:RSA1024 Port=%d\n", port[i]); fscanf(ctx->rsock, "%d", &err); diff --git a/src/tor_ctl.h b/src/tor_ctl.h index 720513b..e7d4518 100644 --- a/src/tor_ctl.h +++ b/src/tor_ctl.h @@ -14,6 +14,11 @@ struct tor_ctl { FILE* wsock; }; +enum TOR_ONION_FLAGS { + TOR_ONION_FLAG_NONE = 0, + TOR_ONION_FLAG_NON_ANONYMOUS = 1 << 0 +}; + int tor_ctl_connect(struct tor_ctl* ctx, char* addr, char* service); -int tor_ctl_add_onion(struct tor_ctl* ctx, struct tor_os_str* tos, uint16_t* port); +int tor_ctl_add_onion(struct tor_ctl* ctx, struct tor_os_str* tos, uint16_t* port, enum TOR_ONION_FLAGS flags); void tor_ctl_close(struct tor_ctl* ctx); diff --git a/src/tor_echo.c b/src/tor_echo.c index a612a60..f015ece 100644 --- a/src/tor_echo.c +++ b/src/tor_echo.c @@ -7,7 +7,7 @@ #include "net_tools.h" #include "url.h" -void te_create_onion_services(struct tor_os_str* tos, struct tor_ctl* tctl, uint16_t* ports, int ports_count) { +void te_create_onion_services(struct tor_os_str* tos, struct tor_ctl* tctl, uint16_t* ports, int ports_count, enum TOR_ONION_FLAGS tof) { tor_os_create (tos, "onion_services.pub", "onion_services.txt", ports_count); tor_os_read (tos); @@ -17,7 +17,7 @@ void te_create_onion_services(struct tor_os_str* tos, struct tor_ctl* tctl, uint fprintf(stderr, "Unable to open Tor Socket\n"); exit(EXIT_FAILURE); } - err = tor_ctl_add_onion (tctl, tos, ports); + err = tor_ctl_add_onion (tctl, tos, ports, tof); if (err != 0) { fprintf(stderr, "Unable to create Onion Services (error: %d)\n", err); exit(EXIT_FAILURE); @@ -83,14 +83,26 @@ int main(int argc, char** argv) { setvbuf(stdout, NULL, _IONBF, 0); printf("~ torecho ~\n"); - int tcp_serv_sock = 0, err; + int tcp_serv_sock = 0, err, opt; struct evt_core_ctx evts = {0}; uint16_t ports[] = {7500}; int ports_count = sizeof(ports[0]) / sizeof(ports); struct tor_os_str tos; struct tor_ctl tctl; + enum TOR_ONION_FLAGS tof = TOR_ONION_FLAG_NONE; char url[1024]; + + while ((opt = getopt(argc, argv, "n")) != -1) { + switch(opt) { + case 'n': + tof |= TOR_ONION_FLAG_NON_ANONYMOUS; + break; + default: + break; + } + } + // 1. Register categories struct evt_core_cat tcp_co = { .app_ctx = NULL, @@ -116,7 +128,7 @@ int main(int argc, char** argv) { printf("--- Categories created\n"); // 2. Create or load onion services - te_create_onion_services (&tos, &tctl, ports, ports_count); + te_create_onion_services (&tos, &tctl, ports, ports_count, tof); printf("--- Onion services created\n"); // 3. Create TCP server diff --git a/torrc_single_hop b/torrc_single_hop new file mode 100644 index 0000000..08c7295 --- /dev/null +++ b/torrc_single_hop @@ -0,0 +1,7 @@ +ControlPort 9051 +SOCKSPort 0 +UseEntryGuards 0 +SafeLogging 0 +HiddenServiceNonAnonymousMode 1 +HiddenServiceSingleHopMode 1 +#Log INFO stdout