Fake Tor OS now create connections
This commit is contained in:
parent
ccd8fb68a7
commit
7eab91cae8
8 changed files with 63 additions and 22 deletions
|
@ -183,7 +183,7 @@ struct block_info {
|
||||||
char reason[1024];
|
char reason[1024];
|
||||||
};
|
};
|
||||||
|
|
||||||
void on_block (struct evt_core_ctx* ctx, void* raw) {
|
enum DONAR_TIMER_DECISION on_block (struct evt_core_ctx* ctx, void* raw) {
|
||||||
struct block_info* bi = raw;
|
struct block_info* bi = raw;
|
||||||
struct thunder_ctx* thunderc = bi->app_ctx->misc;
|
struct thunder_ctx* thunderc = bi->app_ctx->misc;
|
||||||
|
|
||||||
|
@ -195,6 +195,7 @@ void on_block (struct evt_core_ctx* ctx, void* raw) {
|
||||||
|
|
||||||
release:
|
release:
|
||||||
if (bi->is_timeout) free(bi);
|
if (bi->is_timeout) free(bi);
|
||||||
|
return DONAR_TIMER_STOP;
|
||||||
}
|
}
|
||||||
|
|
||||||
int is_in_order(struct thunder_ctx* thunderc, uint8_t link_id) {
|
int is_in_order(struct thunder_ctx* thunderc, uint8_t link_id) {
|
||||||
|
|
|
@ -43,7 +43,7 @@ failed:
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void reinit_socks5(struct evt_core_ctx* ctx, void* user_data) {
|
enum DONAR_TIMER_DECISION reinit_socks5(struct evt_core_ctx* ctx, void* user_data) {
|
||||||
// @FIXME: Ugly way to get donar_client_ctx. Shame on me :/
|
// @FIXME: Ugly way to get donar_client_ctx. Shame on me :/
|
||||||
struct evt_core_cat* cat = evt_core_get_from_cat (ctx, "socks5-failed");
|
struct evt_core_cat* cat = evt_core_get_from_cat (ctx, "socks5-failed");
|
||||||
if (cat == NULL) {
|
if (cat == NULL) {
|
||||||
|
@ -55,6 +55,7 @@ void reinit_socks5(struct evt_core_ctx* ctx, void* user_data) {
|
||||||
|
|
||||||
fprintf(stdout, "[%s][donar-client] We have waited enough, retriggering socks5 for port %ld\n", current_human_datetime (), pos+7500);
|
fprintf(stdout, "[%s][donar-client] We have waited enough, retriggering socks5 for port %ld\n", current_human_datetime (), pos+7500);
|
||||||
init_socks5_client (app_ctx, pos);
|
init_socks5_client (app_ctx, pos);
|
||||||
|
return DONAR_TIMER_STOP;
|
||||||
}
|
}
|
||||||
|
|
||||||
int on_socks5_failed(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo) {
|
int on_socks5_failed(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo) {
|
||||||
|
|
|
@ -119,6 +119,10 @@ void donar_server(struct donar_server_ctx* ctx, struct donar_params* dp) {
|
||||||
for (uint16_t i = 0; i < dp->links ; i++) {
|
for (uint16_t i = 0; i < dp->links ; i++) {
|
||||||
ctx->ports[i] = 7500 + i;
|
ctx->ports[i] = 7500 + i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
create_onion_services (&(ctx->tos), &(ctx->tctl), ctx->ports, dp->links, dp->tof);
|
||||||
ugly_global_tctl = &(ctx->tctl);
|
ugly_global_tctl = &(ctx->tctl);
|
||||||
/*struct donar_server_os_republish_params dsorp = { .dctx = ctx, dp = dp};
|
/*struct donar_server_os_republish_params dsorp = { .dctx = ctx, dp = dp};
|
||||||
|
@ -126,9 +130,6 @@ void donar_server(struct donar_server_ctx* ctx, struct donar_params* dp) {
|
||||||
set_timeout(&(ctx->evts), 1000, &dsorp, republish_tor_os); */
|
set_timeout(&(ctx->evts), 1000, &dsorp, republish_tor_os); */
|
||||||
printf("--- Onion services created\n");
|
printf("--- Onion services created\n");
|
||||||
|
|
||||||
init_tcp_servers(ctx, dp->links);
|
|
||||||
printf("--- TCP servers are listening\n");
|
|
||||||
|
|
||||||
g_ptr_array_foreach (dp->remote_ports, (void(*)(void*, void*))init_udp_remote, &(ctx->evts));
|
g_ptr_array_foreach (dp->remote_ports, (void(*)(void*, void*))init_udp_remote, &(ctx->evts));
|
||||||
printf("--- Remote ports are binded locally\n");
|
printf("--- Remote ports are binded locally\n");
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include "evt_core.h"
|
#include "evt_core.h"
|
||||||
#include "socks5.h"
|
#include "socks5.h"
|
||||||
#include "tor_ctl.h"
|
#include "tor_ctl.h"
|
||||||
|
#include "timer.h"
|
||||||
|
|
||||||
int faketor_socks5_listen(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo) {
|
int faketor_socks5_listen(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo) {
|
||||||
int conn_sock1;
|
int conn_sock1;
|
||||||
|
@ -48,20 +49,17 @@ co_error:
|
||||||
}
|
}
|
||||||
|
|
||||||
int faketor_socks5_server_success(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo) {
|
int faketor_socks5_server_success(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo) {
|
||||||
printf("success!\n");
|
printf("success socks5!\n");
|
||||||
struct socks5_ctx *s5ctx = fdinfo->other;
|
|
||||||
|
|
||||||
return EVT_CORE_FD_EXHAUSTED;
|
return EVT_CORE_FD_EXHAUSTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
int faketor_socks5_server_failed(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo) {
|
int faketor_socks5_server_failed(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo) {
|
||||||
printf("failure!\n");
|
printf("failure socks5!\n");
|
||||||
return EVT_CORE_FD_EXHAUSTED;
|
return EVT_CORE_FD_EXHAUSTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
int faketor_torctl_server_success(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo) {
|
int faketor_torctl_server_success(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo) {
|
||||||
printf("success!\n");
|
printf("success torctl!\n");
|
||||||
evt_core_mv_fd2(ctx, fdinfo, "");
|
|
||||||
|
|
||||||
return EVT_CORE_FD_EXHAUSTED;
|
return EVT_CORE_FD_EXHAUSTED;
|
||||||
}
|
}
|
||||||
|
@ -203,6 +201,7 @@ int main(void) {
|
||||||
fdinfo.url = "control:listen:9051";
|
fdinfo.url = "control:listen:9051";
|
||||||
evt_core_add_fd(&evts, &fdinfo);
|
evt_core_add_fd(&evts, &fdinfo);
|
||||||
|
|
||||||
|
init_timer (&evts);
|
||||||
socks5_server_init(&evts);
|
socks5_server_init(&evts);
|
||||||
tor_ctl_server_init (&evts);
|
tor_ctl_server_init (&evts);
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,8 @@ int create_ip_client(char* host, char* service, int type) {
|
||||||
|
|
||||||
if (cursor == NULL) {
|
if (cursor == NULL) {
|
||||||
fprintf(stderr, "No connect worked for %s:%s\n", host, service);
|
fprintf(stderr, "No connect worked for %s:%s\n", host, service);
|
||||||
exit(EXIT_FAILURE);
|
return -1;
|
||||||
|
//exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
freeaddrinfo(result);
|
freeaddrinfo(result);
|
||||||
|
@ -45,6 +46,7 @@ int create_ip_client(char* host, char* service, int type) {
|
||||||
|
|
||||||
int create_tcp_client(char* host, char* service) {
|
int create_tcp_client(char* host, char* service) {
|
||||||
int sock = create_ip_client (host, service, SOCK_STREAM);
|
int sock = create_ip_client (host, service, SOCK_STREAM);
|
||||||
|
if (sock < 0) return sock;
|
||||||
int activate = 1;
|
int activate = 1;
|
||||||
int err;
|
int err;
|
||||||
err = setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, &activate, sizeof(activate));
|
err = setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, &activate, sizeof(activate));
|
||||||
|
@ -102,6 +104,7 @@ int create_ip_server(char* host, char* service, int type) {
|
||||||
|
|
||||||
int create_tcp_server(char* host, char* service) {
|
int create_tcp_server(char* host, char* service) {
|
||||||
int sock = create_ip_server (host, service, SOCK_STREAM);
|
int sock = create_ip_server (host, service, SOCK_STREAM);
|
||||||
|
if (sock < 0) return sock;
|
||||||
int activate = 1;
|
int activate = 1;
|
||||||
int err;
|
int err;
|
||||||
err = setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, &activate, sizeof(activate));
|
err = setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, &activate, sizeof(activate));
|
||||||
|
|
|
@ -21,10 +21,10 @@ int set_timeout_handle(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
struct timer_ctx* tctx = fdinfo->other;
|
struct timer_ctx* tctx = fdinfo->other;
|
||||||
tctx->cb(ctx, tctx->user_ctx);
|
enum DONAR_TIMER_DECISION dtd = tctx->cb(ctx, tctx->user_ctx);
|
||||||
|
|
||||||
evt_core_rm_fd(ctx, fdinfo->fd);
|
if (dtd == DONAR_TIMER_STOP) evt_core_rm_fd(ctx, fdinfo->fd);
|
||||||
return 1;
|
return EVT_CORE_FD_EXHAUSTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
void init_timer(struct evt_core_ctx* evts) {
|
void init_timer(struct evt_core_ctx* evts) {
|
||||||
|
|
|
@ -2,7 +2,11 @@
|
||||||
#include <sys/timerfd.h>
|
#include <sys/timerfd.h>
|
||||||
#include "evt_core.h"
|
#include "evt_core.h"
|
||||||
|
|
||||||
typedef void (*timer_cb)(struct evt_core_ctx* ctx, void* user_data);
|
enum DONAR_TIMER_DECISION {
|
||||||
|
DONAR_TIMER_STOP,
|
||||||
|
DONAR_TIMER_CONTINUE,
|
||||||
|
};
|
||||||
|
typedef enum DONAR_TIMER_DECISION (*timer_cb)(struct evt_core_ctx* ctx, void* user_data);
|
||||||
void init_timer(struct evt_core_ctx* evts);
|
void init_timer(struct evt_core_ctx* evts);
|
||||||
int set_timeout(struct evt_core_ctx* evts, uint64_t milli_sec, void* ctx, timer_cb cb);
|
int set_timeout(struct evt_core_ctx* evts, uint64_t milli_sec, void* ctx, timer_cb cb);
|
||||||
void stop_timer(struct evt_core_ctx* evts);
|
void stop_timer(struct evt_core_ctx* evts);
|
||||||
|
|
|
@ -1,4 +1,30 @@
|
||||||
#include "tor_ctl.h"
|
#include "tor_ctl.h"
|
||||||
|
#include "timer.h"
|
||||||
|
|
||||||
|
struct os_connect {
|
||||||
|
char host[256];
|
||||||
|
char port[6];
|
||||||
|
char url[512];
|
||||||
|
};
|
||||||
|
|
||||||
|
enum DONAR_TIMER_DECISION on_os_connect_timeout(struct evt_core_ctx* ctx, void* user_data) {
|
||||||
|
struct os_connect *oc = user_data;
|
||||||
|
struct evt_core_fdinfo newfdinfo;
|
||||||
|
struct evt_core_cat newcat;
|
||||||
|
newfdinfo.cat = &newcat;
|
||||||
|
newfdinfo.url = oc->url;
|
||||||
|
|
||||||
|
int fd = create_tcp_client(oc->host, oc->port);
|
||||||
|
if (fd <= 0) return DONAR_TIMER_CONTINUE;
|
||||||
|
|
||||||
|
newfdinfo.fd = fd;
|
||||||
|
newfdinfo.cat->name = "torctl-server-success";
|
||||||
|
struct evt_core_fdinfo *reg = evt_core_add_fd (ctx, &newfdinfo);
|
||||||
|
|
||||||
|
printf("[%s][torctl] onion service %s up (cat: %s, fd: %d)\n", current_human_datetime (), reg->url, reg->cat->name, reg->fd);
|
||||||
|
free(oc);
|
||||||
|
return DONAR_TIMER_STOP;
|
||||||
|
}
|
||||||
|
|
||||||
int tor_ctl_connect(struct tor_ctl* ctx, char* addr, char* service) {
|
int tor_ctl_connect(struct tor_ctl* ctx, char* addr, char* service) {
|
||||||
int sock = create_tcp_client (addr, service);
|
int sock = create_tcp_client (addr, service);
|
||||||
|
@ -156,9 +182,9 @@ int on_torctl_server_auth_write(struct evt_core_ctx* ctx, struct evt_core_fdinfo
|
||||||
|
|
||||||
int on_torctl_server_add_onion_read(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo) {
|
int on_torctl_server_add_onion_read(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo) {
|
||||||
char buffer[1024] = {0};
|
char buffer[1024] = {0};
|
||||||
char host[1024] = {0};
|
|
||||||
char *strtok_ptr, *str_target, *token;
|
char *strtok_ptr, *str_target, *token;
|
||||||
int i, port1, port2;
|
int i, port1;
|
||||||
|
char *service_id = "iu7aeep42k5ky3fwcfag5el2raelfcwuilsstqhcz3c6bmxilr2nuayd.onion"; //@FIXME hardcoded url
|
||||||
|
|
||||||
ssize_t nread = recv(fdinfo->fd, buffer, sizeof(buffer), MSG_PEEK);
|
ssize_t nread = recv(fdinfo->fd, buffer, sizeof(buffer), MSG_PEEK);
|
||||||
if (nread == -1 && errno == EAGAIN) return EVT_CORE_FD_EXHAUSTED;
|
if (nread == -1 && errno == EAGAIN) return EVT_CORE_FD_EXHAUSTED;
|
||||||
|
@ -183,11 +209,16 @@ int on_torctl_server_add_onion_read(struct evt_core_ctx* ctx, struct evt_core_fd
|
||||||
if (i < 2) continue;
|
if (i < 2) continue;
|
||||||
if (token == NULL) break;
|
if (token == NULL) break;
|
||||||
|
|
||||||
int captured = sscanf(token, "Port=%d,%[^:]:%d", &port1, host, &port2);
|
struct os_connect *oc = malloc(sizeof(struct os_connect));
|
||||||
if (captured != 3) continue;
|
int captured = sscanf(token, "Port=%d,%[^:]:%s", &port1, oc->host, oc->port);
|
||||||
|
if (captured != 3) {
|
||||||
|
free(oc);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
//create_tcp_client();
|
sprintf(oc->url, "torctl:%s:%d", service_id, port1);
|
||||||
printf("Captured internet: %d, target: %s %d\n", port1, host, port2);
|
printf("[%s][torctl] will create onion service %s:%d <-> %s:%s in background (%s)\n", current_human_datetime (), service_id, port1, oc->host, oc->port, oc->url);
|
||||||
|
set_timeout(ctx, 100, oc, on_os_connect_timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
evt_core_mv_fd2 (ctx, fdinfo, "torctl-server-add-onion-write");
|
evt_core_mv_fd2 (ctx, fdinfo, "torctl-server-add-onion-write");
|
||||||
|
@ -195,6 +226,7 @@ int on_torctl_server_add_onion_read(struct evt_core_ctx* ctx, struct evt_core_fd
|
||||||
}
|
}
|
||||||
|
|
||||||
int on_torctl_server_add_onion_write(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo) {
|
int on_torctl_server_add_onion_write(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo) {
|
||||||
|
//@FIXME hardcoded response
|
||||||
char *answer = "250-ServiceID=iu7aeep42k5ky3fwcfag5el2raelfcwuilsstqhcz3c6bmxilr2nuayd\r\n250-PrivateKey=ED25519-V3:ULk3Q/TFqngKCDDzeM93YC80IDOjz13PKTx718UjE0Svf+u/QZmN9EHzUCqCa1ZkNAXSQJIzcOVeJ8OL8Zg5Xg==\r\n250 OK\r\n";
|
char *answer = "250-ServiceID=iu7aeep42k5ky3fwcfag5el2raelfcwuilsstqhcz3c6bmxilr2nuayd\r\n250-PrivateKey=ED25519-V3:ULk3Q/TFqngKCDDzeM93YC80IDOjz13PKTx718UjE0Svf+u/QZmN9EHzUCqCa1ZkNAXSQJIzcOVeJ8OL8Zg5Xg==\r\n250 OK\r\n";
|
||||||
|
|
||||||
ssize_t nwrite;
|
ssize_t nwrite;
|
||||||
|
|
Loading…
Reference in a new issue