WIP refactor socks5

This commit is contained in:
Quentin Dufour 2019-03-21 13:01:48 +01:00
parent ce623a50cf
commit f43437978c
2 changed files with 34 additions and 4 deletions

View file

@ -1,13 +1,43 @@
#include "socks5.h" #include "socks5.h"
int socks5_handshake_syn(int sock) { struct socks5_ctx {
//@TODO: Refactor the client handshake management struct client_handshake ch;
struct server_handshake sh;
struct client_request cr;
char cr_buffer[262];
struct server_reply sr;
};
void socks5_free_ctx(void* elem) {
struct socks5_ctx* ctx = elem;
free(ctx);
}
void create_socks5_dns_client(struct evt_core_ctx* ctx, char* proxy_host, char* proxy_port, char* addr, uint16_t port) {
int sock = create_tcp_client (proxy_host, proxy_port);
struct evt_core_fdinfo fdinfo;
struct evt_core_cat cat;
fdinfo.cat = &cat;
fdinfo.cat->name = "socks5-send-handshake";
fdinfo.fd = sock;
fdinfo.other = malloc(sizeof(struct socks5_ctx));
if (fdinfo.other == NULL) {
perror("malloc failed");
exit(EXIT_FAILURE);
}
fdinfo.free_other = socks5_free_ctx;
evt_core_add_fd (ctx, &fdinfo);
}
int socks5_handshake_syn(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo) {
struct client_handshake ch = { struct client_handshake ch = {
.ver = 0x05, .ver = 0x05,
.nmethods = 0x01, .nmethods = 0x01,
.methods = {0x00} .methods = {0x00}
}; };
fdinfo->
int size = sizeof(uint8_t) * (2 + ch.nmethods); int size = sizeof(uint8_t) * (2 + ch.nmethods);
if (size != write(sock, &ch, size)) { if (size != write(sock, &ch, size)) {
perror("write failed on tcp socket in socks5"); perror("write failed on tcp socket in socks5");
@ -17,7 +47,6 @@ int socks5_handshake_syn(int sock) {
} }
int socks5_handshake_ack(int sock) { int socks5_handshake_ack(int sock) {
//@TODO: Refactor the client handshake management
struct client_handshake ch = { struct client_handshake ch = {
.ver = 0x05, .ver = 0x05,
.nmethods = 0x01, .nmethods = 0x01,

View file

@ -7,6 +7,7 @@
#include <netdb.h> #include <netdb.h>
#include <string.h> #include <string.h>
#include "net_tools.h" #include "net_tools.h"
#include "evt_core.h"
enum socks5_state { enum socks5_state {
SOCKS5_STATE_NEW, SOCKS5_STATE_NEW,
@ -95,7 +96,7 @@ struct server_reply {
uint16_t port; uint16_t port;
}; };
int socks5_handshake_syn(int sock); int socks5_handshake_syn(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo);
int socks5_handshake_ack(int sock); int socks5_handshake_ack(int sock);
int socks5_connect_dns(int sock, char* addr, uint16_t port); int socks5_connect_dns(int sock, char* addr, uint16_t port);
int socks5_reply(int sock); int socks5_reply(int sock);