Skip to content

Commit

Permalink
jsset is working for pure javascript file. there is a double eofing p…
Browse files Browse the repository at this point in the history
…roblem on circuits which need to be investigated
  • Loading branch information
vmon committed Aug 5, 2016
1 parent e534c68 commit af8cfae
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 172 deletions.
2 changes: 1 addition & 1 deletion setup_st_client.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
#killall stegotorus

#http
#http and only js
./stegotorus --log-min-severity=debug --timestamp-logs chop client --trace-packets --disable-retransmit 127.0.0.1:4999 http 127.0.0.1:5000 --steg-mod js #2> /tmp/client_out.txt

#./stegotorus --log-min-severity=debug --timestamp-logs chop client --trace-packets --disable-retransmit 127.0.0.1:4999 http_apache 127.0.0.1:5000 #2> /tmp/client_out.txt
2 changes: 1 addition & 1 deletion setup_st_server.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
killall stegotorus

./stegotorus --log-min-severity=debug --timestamp-logs chop server --trace-packets --disable-retransmit 127.0.0.1:5001 $1 127.0.0.1:5000 --steg-mod js #2> /tmp/server_out.txt&
./stegotorus --log-min-severity=debug --timestamp-logs chop server --trace-packets --disable-retransmit 127.0.0.1:5001 http $1 127.0.0.1:5000 --steg-mod js #2> /tmp/server_out.txt&

#http_apache
#./stegotorus --log-min-severity=debug --timestamp-logs chop server --trace-packets --disable-retransmit --minimum-noise-to-signal 0 --cover-server 108.174.48.210 --cover-list apache_payload/equalitie_items.cvs 127.0.0.1:5001 127.0.0.1:5000 $1 #2> ~/tmp/server_out.txt&
Expand Down
27 changes: 16 additions & 11 deletions src/steg/http.cc
Original file line number Diff line number Diff line change
Expand Up @@ -372,12 +372,12 @@ http_steg_t::http_client_cookie_transmit (evbuffer *source, conn_t *conn)
{
struct evbuffer *dest = conn->outbound();
size_t sbuflen = evbuffer_get_length(source);
int bufsize = 10000;
char* buf = (char*) xmalloc(bufsize);
const int bufsize = 10000; //TOOD: this shouldn't be defined here, this is a universal constant
char buf[bufsize];

char* data;
char* data2 = (char*) xmalloc (sbuflen*4);
char* cookiebuf = (char*) xmalloc (sbuflen*8);
char data2[sbuflen*4];
char cookiebuf[sbuflen*8];
size_t payload_len = 0;
size_t cnt = 0;
size_t cookie_len = 0;
Expand All @@ -399,7 +399,7 @@ http_steg_t::http_client_cookie_transmit (evbuffer *source, conn_t *conn)

// retry up to 10 times
while (!payload_len) {
payload_len = config->payload_server->find_client_payload(buf, bufsize,
payload_len = config->payload_server->find_client_payload((char*)buf, bufsize,
TYPE_HTTP_REQUEST);
if (cnt++ == 10) {
goto err;
Expand Down Expand Up @@ -474,19 +474,16 @@ http_steg_t::http_client_cookie_transmit (evbuffer *source, conn_t *conn)
transmit_len += 4;

evbuffer_drain(source, sbuflen);
log_debug("CLIENT TRANSMITTED payload %d\n", (int) sbuflen);
type = 1; //config->payload_server->find_uri_type(buf, payload_len);

//log_debug("CLIENT TRANSMITTED payload %d requesting type %d\n", (int) sbuflen, type);
conn->cease_transmission();

type = config->payload_server->find_uri_type(buf, bufsize);
have_transmitted = true;

free(buf);
free(data2);
return transmit_len;

err:
free(buf);
free(data2);
return -1;

}
Expand Down Expand Up @@ -674,6 +671,10 @@ http_steg_t::transmit(struct evbuffer *source)

if (rval >= 0) {
have_transmitted = 1;
if (type == -1) {
log_debug(conn, "have transmited with invalid type!!!");
}

// FIXME: should decide whether or not to do this based on the
// Connection: header. (Needs additional changes elsewhere, esp.
// in transmit_room.)
Expand Down Expand Up @@ -789,6 +790,10 @@ http_steg_t::http_client_receive(evbuffer *source, evbuffer *dest)
int rval = RECV_BAD;

//basic sanity check
if (!(0 < type && type <= (signed) c_no_of_steg_protocol && (config->file_steg_mods.find(type) != config->file_steg_mods.end())))
{
log_debug(conn,"something is phishy");
}
log_assert(0 < type && type <= (signed) c_no_of_steg_protocol && (config->file_steg_mods.find(type) != config->file_steg_mods.end()));
//This just to make sure that the steg mod is initialized. if the content isn't actually of type .type, then the steg mod will reject it
//gracefully
Expand Down
84 changes: 3 additions & 81 deletions src/steg/http_steg_mods/file_steg.cc
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,6 @@ FileStegMod::http_server_transmit(evbuffer *source, conn_t *conn)

uint8_t* data1;
int sbuflen = 0;
//int gzipMode = JS_GZIP_RESP;
//call this from util to find to extract the buffer into memory block
if (c_content_type != HTTP_CONTENT_JAVASCRIPT /*|| CONTENT_HTML_JAVASCRIPT*/) {
sbuflen = evbuffer_to_memory_block(source, &data1);
}

ssize_t outbuflen = 0;
ssize_t body_offset = 0;
Expand All @@ -167,10 +162,8 @@ FileStegMod::http_server_transmit(evbuffer *source, conn_t *conn)
size_t body_len = 0;
size_t hLen = 0;

if (c_content_type == HTTP_CONTENT_JAVASCRIPT/*|| CONTENT_HTML_JAVASCRIPT*/) {
//cnt = 0;
sbuflen = JS_evbuffer_to_memory_block(source, &data1); //actually returns size_t instead of int
}
//call this from util to find to extract the buffer into memory block
sbuflen = evbuffer_to_memory_block(source, &data1);

if (sbuflen < 0 /*&& c_content_type != HTTP_CONTENT_JAVASCRIPT || CONTENT_HTML_JAVASCRIPT*/) {
log_warn("unable to extract the data from evbuffer");
Expand Down Expand Up @@ -225,7 +218,7 @@ FileStegMod::http_server_transmit(evbuffer *source, conn_t *conn)

//If everything seemed to be fine, New steg module test:
if (!(LOG_SEV_DEBUG < log_get_min_severity())) { //only perform this during debug
uint8_t recovered_data_for_test[sbuflen];
uint8_t recovered_data_for_test[HTTP_MSG_BUF_SIZE]; //this is the size we have promised to decode func
decode(outbuf, outbuflen, recovered_data_for_test);

if (memcmp(data1, recovered_data_for_test, sbuflen)) { //barf!!
Expand Down Expand Up @@ -308,14 +301,6 @@ FileStegMod::http_client_receive(conn_t *conn, struct evbuffer *dest,
int content_len = 0, outbuflen;
uint8_t *httpHdr, *httpBody;




int i, j, k;
//ev_ssize_t r;
struct evbuffer * scratch; //maybe move to filesteg class?
char c;

log_debug("Entering CLIENT receive");

ssize_t body_offset = extract_appropriate_respones_body(source);
Expand Down Expand Up @@ -367,67 +352,6 @@ FileStegMod::http_client_receive(conn_t *conn, struct evbuffer *dest,

log_debug("CLIENT unwrapped data of length %d:", outbuflen);

if( c_content_type == HTTP_CONTENT_JAVASCRIPT ) {

outbuf[outbuflen] = 0;
if (outbuflen % 2) {
log_debug("CLIENT ERROR: An odd number of hex characters received\n");
return RECV_BAD;
}

if (! isxString((char *)outbuf)) {
log_debug("CLIENT ERROR: Data received not hex");
return RECV_BAD;
}

// log_debug("Hex data received:");
// buf_dump ((unsigned char*)data, decCnt, stderr);

// get a scratch buffer
scratch = evbuffer_new();
if (!scratch) return RECV_BAD;

if (evbuffer_expand(scratch, outbuflen/2)) {
log_warn("CLIENT ERROR: Evbuffer expand failed \n");
evbuffer_free(scratch);
return RECV_BAD;
}

// convert hex data back to binary
for (i=0, j=0; i< outbuflen; i=i+2, ++j) {
sscanf((const char *) &outbuf[i], "%2x", (unsigned int*) &k);
c = (char)k;
evbuffer_add(scratch, &c, 1);
}

if (evbuffer_add_buffer(dest, scratch)) {
evbuffer_free(scratch);
log_warn("CLIENT ERROR: Failed to transfer buffer");
return RECV_BAD;
}
log_debug("Added scratch (buffer) to dest\n");

evbuffer_free(scratch);


if (response_len <= evbuffer_get_length(source)) {
if (evbuffer_drain(source, response_len) == -1) {
log_warn("CLIENT ERROR: Failed to drain source");
return RECV_BAD;
}
}
else {
log_warn("response_len > buffer size... can't drain");
exit(-1);
}


log_debug("Drained source for %d char\n", response_len);

// downcast_steg(s)->have_received = 1;
}

else {
if (evbuffer_add(dest, outbuf, outbuflen)) {
log_warn("CLIENT ERROR: evbuffer_add to dest fails\n");
return RECV_BAD;
Expand All @@ -437,8 +361,6 @@ FileStegMod::http_client_receive(conn_t *conn, struct evbuffer *dest,
log_warn("CLIENT ERROR: failed to drain source\n");
return RECV_BAD;
}

}

conn->expect_close();
return RECV_GOOD;
Expand Down
Loading

0 comments on commit af8cfae

Please sign in to comment.