Skip to content

Commit

Permalink
stream prep and socks work.
Browse files Browse the repository at this point in the history
  • Loading branch information
ianamason committed Aug 7, 2014
1 parent b102c7a commit c799f30
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 5 deletions.
14 changes: 14 additions & 0 deletions src/network.cc
Original file line number Diff line number Diff line change
Expand Up @@ -852,13 +852,27 @@ create_outbound_connections_socks(circuit_t *ckt)
goto failure;
}



/* XXXX Feed socks state through the protocol and get a connection set.
This is a stopgap. */

if (ckt->cfg()->ignore_socks_destination) {
// if in managed_mode then use the IP address received from socks

This comment has been minimized.

Copy link
@BaronWolfenstein

BaronWolfenstein Aug 13, 2014

The roadmap for changing the API is sometime next May -- this will have to do for now.

// the port gets ignored, because the config file could specify
// multiple services. The right way to fix this is to change the
// Tor pluggable transports API to allow client side options

if (_managed_mode) {
cfg->socks_force_addr(host, port);
}

create_outbound_connections(ckt, true);
return;
}



buf = bufferevent_socket_new(cfg->base, -1, BEV_OPT_CLOSE_ON_FREE);
if (!buf) {
log_warn(ckt, "unable to create outbound socket buffer");
Expand Down
7 changes: 6 additions & 1 deletion src/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ class config_t
the address to which the socket is bound. */

virtual conn_t *conn_create(size_t index) = 0;

virtual void socks_force_addr(const char* host, int port) = 0;


};

int config_is_supported(const char *name);
Expand Down Expand Up @@ -148,7 +152,8 @@ extern const proto_module *const supported_protos[];
virtual evutil_addrinfo *get_target_addrs(size_t n) const; \
virtual const steg_config_t *get_steg(size_t n) const; \
virtual circuit_t *circuit_create(size_t index); \
virtual conn_t *conn_create(size_t index) \
virtual conn_t *conn_create(size_t index); \
virtual void socks_force_addr(const char* host, int port) \
/* deliberate absence of semicolon */

#define CONFIG_STEG_STUBS(mod) \
Expand Down
21 changes: 21 additions & 0 deletions src/protocol/chop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,27 @@ chop_config_t::init(int n_options, const char *const *options, modus_operandi_t
}




void chop_config_t::socks_force_addr(const char* host, int port) {
char port_buf[8];
sprintf(port_buf, "%d", port);

struct evutil_addrinfo* addr = resolve_address_port(host, 1, 0, port_buf);

for (vector<struct evutil_addrinfo *>::iterator i = down_addresses.begin();
i != down_addresses.end(); i++) {
// just change the addresses, keep the ports the same
struct sockaddr_in* daddr = (struct sockaddr_in*) ((*i)->ai_addr);
daddr->sin_addr.s_addr = ((struct sockaddr_in*) addr->ai_addr)->sin_addr.s_addr;
}

evutil_freeaddrinfo(addr);

}



struct evutil_addrinfo *
chop_config_t::get_listen_addrs(size_t n) const
{
Expand Down
3 changes: 2 additions & 1 deletion src/protocol/chop_circuit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -762,10 +762,11 @@ chop_circuit_t::recv_block(uint32_t seqno, opcode_t op, evbuffer *data)

switch (op) {
case op_DAT:
case op_FIN:
//case op_FIN:
// No special handling required.
goto insert;

case op_FIN:
case op_RST:
// Remote signaled a protocol error. Disconnect.
log_info(this, "received RST; disconnecting circuit");
Expand Down
14 changes: 14 additions & 0 deletions src/protocol/null.cc
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,20 @@ null_config_t::init(int n_options, const char *const *options, modus_operandi_t
return false;
}



void null_config_t::socks_force_addr(const char* host, int port) {

This comment has been minimized.

Copy link
@BaronWolfenstein

BaronWolfenstein Aug 13, 2014

This is when no config file is present?

This comment has been minimized.

Copy link
@ianamason

ianamason Aug 13, 2014

Author Member

No null is a protocol like http. It can be configured by using config files just like http.

char port_buf[8];
sprintf(port_buf, "%d", port);

evutil_freeaddrinfo(this->target_addr);

This comment has been minimized.

Copy link
@BaronWolfenstein

BaronWolfenstein Aug 13, 2014

What would be the best way to test this?

// this may not be right...
this->target_addr = resolve_address_port(host, 1, 0, port_buf);


}


/** Retrieve the 'n'th set of listen addresses for this configuration. */
struct evutil_addrinfo *
null_config_t::get_listen_addrs(size_t n) const
Expand Down
6 changes: 6 additions & 0 deletions src/steg/headers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,12 @@ get_content_encoding(char* headers, size_t headers_length, char** encodingp, siz
return get_header_value(headers, headers_length, encodingp, vlength, HTTP_HEADERS_CONTENT_ENCODING);
}

rcode_t
get_content_type(char* headers, size_t headers_length, char** typep, size_t& vlength)
{
return get_header_value(headers, headers_length, typep, vlength, HTTP_HEADERS_CONTENT_TYPE);
}


bool
is_gzip_encoded(char *headers, size_t headers_length)
Expand Down
4 changes: 4 additions & 0 deletions src/steg/headers.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ typedef enum methods {
#define HTTP_HEADERS_END "\r\n\r\n"
#define HTTP_HEADERS_EOL "\r\n"
#define HTTP_HEADERS_CONTENT_LENGTH "content-length: "
#define HTTP_HEADERS_CONTENT_TYPE "content-type: "
#define HTTP_HEADERS_ACCEPT "accept: "
#define HTTP_HEADERS_ACCEPT_ENCODING "accept-encoding: "
#define HTTP_HEADERS_CONTENT_ENCODING "content-encoding: "
Expand All @@ -54,6 +55,7 @@ typedef enum HTTP_CONTENT_TYPES {
HTTP_CONTENT_JSON,
HTTP_CONTENT_JPEG,
HTTP_CONTENT_RAW,
HTTP_CONTENT_MJPEG,
HTTP_CONTENT_TYPES_MAX
} http_content_t;

Expand All @@ -71,10 +73,12 @@ int get_http_status_code(char* headers, size_t headers_length);
http_method_t get_method(char* headers, size_t headers_length);
rcode_t get_cookie(char* headers, size_t headers_length, char** cookiep, size_t& cookie_length);
rcode_t get_content_length(char* headers, size_t headers_length, size_t& content_length);
rcode_t get_content_type(char* headers, size_t headers_length, char** typep, size_t& vlength);
rcode_t get_accept(char* headers, size_t headers_length, char** acceptp, size_t& vlength);
rcode_t get_accept_encoding(char* headers, size_t headers_length, char** encodingp, size_t& vlength);
rcode_t get_content_encoding(char* headers, size_t headers_length, char** encodingp, size_t& vlength);


http_content_t find_content_type(char* headers, size_t headers_length);

bool is_gzip_encoded(char* headers, size_t headers_length);
Expand Down
4 changes: 2 additions & 2 deletions src/steg/schemes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ schemes_clientside_init (payloads& payloads, const char* imagedir, const char* p
}

if(enabled_schemes[JPEG_POST]){
payloads.pool = load_images(imagedir);
payloads.pool = load_images(imagedir, 20);
}

if(enabled_schemes[PDF_POST]){
Expand Down Expand Up @@ -385,7 +385,7 @@ schemes_serverside_init (payloads& payloads, const char* imagedir, const char* p
}

if(enabled_schemes[JPEG_POST] || enabled_schemes[JPEG_GET]){
payloads.pool = load_images(imagedir);
payloads.pool = load_images(imagedir, 20);
}

if(enabled_schemes[PDF_POST]){
Expand Down
3 changes: 2 additions & 1 deletion src/steg/shared.cc
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ hex2dest(struct evbuffer *dest, size_t data_length, char *data)
/* get a scratch buffer */
scratch = evbuffer_new();
if (!scratch){
log_warn("scratch evbuffer_new() failed \n");
goto clean_up;
}

Expand Down Expand Up @@ -238,7 +239,7 @@ raw2dest(struct evbuffer *dest, size_t data_length, uchar *data)
goto clean_up;
}

/* make room for the hex data */
/* make room for the raw data */
if (evbuffer_expand(scratch, data_length)) {
log_warn("evbuffer expand failed \n");
goto clean_up;
Expand Down

0 comments on commit c799f30

Please sign in to comment.