Le patchage est total

This commit is contained in:
Quentin 2020-02-27 16:41:52 +01:00
parent 62af0344b1
commit 32ea58c36a
11 changed files with 30 additions and 12 deletions

View file

@ -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;
}

View file

@ -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");

View file

@ -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;

View file

@ -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);
}

View file

@ -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;
};

View file

@ -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));

View file

@ -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 {

View file

@ -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);
}

View file

@ -3,9 +3,16 @@
#include <unistd.h>
#include <errno.h>
#include "proxy.h"
#include "stopwatch.h"
#include <unistd.h>
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)");
}

View file

@ -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 {

View file

@ -11,6 +11,7 @@
* https://ycpcs.github.io/cs365-spring2019/lectures/lecture15.html
*/
struct tor_ctl {
char* os_endpoint;
FILE* rsock;
FILE* wsock;
};