Skip to content

Commit

Permalink
- http_apache steg with updated stegmods successfully tested.
Browse files Browse the repository at this point in the history
- PNGSteg module has migrated to to use vector<uint_8> buffers, activated and tested.
- file extensions now are specified in the related steg modules.
- content-length header is added to HTTP response in case it is missing.
- PayloadScraper migrated to use a map to store the steg modules.
- dead code snippet related to generating HTTP response headers removed.
- has_eligible_HTTP_content mode to trace_payload_server.
  • Loading branch information
vmon committed Jan 5, 2020
1 parent 5eeab0f commit bd460be
Show file tree
Hide file tree
Showing 19 changed files with 482 additions and 515 deletions.
6 changes: 3 additions & 3 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ STEGANOGRAPHERS = \
src/steg/trace_payload_server.cc \
src/steg/payload_scraper.cc \
src/steg/apache_payload_server.cc \
src/steg/http_steg_mods/htmlSteg.cc
src/steg/http_steg_mods/htmlSteg.cc \
src/steg/http_steg_mods/pngSteg.cc
# src/steg/http_steg_mods/gifSteg.cc
# src/steg/http_steg_mods/pdfSteg.cc
# src/steg/http_steg_mods/swfSteg.cc
# src/steg/http_steg_mods/pngSteg.cc
# src/steg/http_steg_mods/gifSteg.cc

libstegotorus_a_SOURCES = \
src/base64.cc \
Expand Down
3 changes: 2 additions & 1 deletion conf.d/chop-http-apache-server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ protocols:
stegs:
- name: "http_apache"
down-address: 127.0.0.1:5000
cover-list: "apache_payload/funnycatpix.csv"
cover-list: "apache_payload/cover_list_puppiesden.csv"
# cover-list: "apache_payload/funnycatpix.csv"
5 changes: 1 addition & 4 deletions src/steg/apache_payload_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
#include "crypt.h"
#include "rng.h"
#include "apache_payload_server.h"

#include "http_steg_mods/file_steg.h"
#include "http_steg_mods/jpgSteg.h"
#include "payload_scraper.h"

using namespace std;
Expand Down Expand Up @@ -52,7 +49,7 @@ ApachePayloadServer::ApachePayloadServer(MachineSide init_side, const string& da
log_debug("payload database does not exists.");
log_debug("scarping payloads to create the database...");

PayloadScraper my_scraper(_database_filename, _apache_host_name, cover_list);
PayloadScraper my_scraper(_database_filename, _apache_host_name, cover_list);
my_scraper.scrape();

}
Expand Down
20 changes: 13 additions & 7 deletions src/steg/http.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ using namespace std;
#include "b64cookies.h"

#include "http_steg_mods/file_steg.h"
// #include "http_steg_mods/swfSteg.h"
// #include "http_steg_mods/pdfSteg.h"
#include "http_steg_mods/jsSteg.h"
#include "http_steg_mods/jpgSteg.h"
// #include "http_steg_mods/pngSteg.h"
#include "http_steg_mods/pngSteg.h"
// #include "http_steg_mods/gifSteg.h"
// #include "http_steg_mods/swfSteg.h"
// #include "http_steg_mods/pdfSteg.h"
#include "http_steg_mods/htmlSteg.h"

#include "http.h"
Expand Down Expand Up @@ -154,16 +154,22 @@ http_steg_config_t::init_file_steg_mods()
//if the steg_mod option has set by the user, only those steg mods
//will be activated otherwise, all other steg mods will be activated

file_steg_mods[HTTP_CONTENT_JPEG] = new JPGSteg(*payload_server, noise2signal);
file_steg_mods[HTTP_CONTENT_PNG] = new PNGSteg(*payload_server, noise2signal);
file_steg_mods[HTTP_CONTENT_JAVASCRIPT] = new JSSteg(*payload_server, noise2signal);
file_steg_mods[HTTP_CONTENT_HTML] = new HTMLSteg(*payload_server, noise2signal);
//TODO:: re-enable when all other Steg mods are migrated to vector<uint_16>
//coverpayload model.
file_steg_mods[HTTP_CONTENT_JPEG] = new JPGSteg(*payload_server, noise2signal);
// file_steg_mods[HTTP_CONTENT_PNG] = new PNGSteg(*payload_server, noise2signal);
// file_steg_mods[HTTP_CONTENT_GIF] = new GIFSteg(*payload_server, noise2signal);
// file_steg_mods[HTTP_CONTENT_SWF] = new SWFSteg(*payload_server, noise2signal);
// file_steg_mods[HTTP_CONTENT_PDF] = new PDFSteg(*payload_server, noise2signal);
file_steg_mods[HTTP_CONTENT_JAVASCRIPT] = new JSSteg(*payload_server, noise2signal);
file_steg_mods[HTTP_CONTENT_HTML] = new HTMLSteg(*payload_server, noise2signal);

//initiate the supported extension list

for(auto cur_steg_mod : file_steg_mods)
for(auto cur_supported_extension: cur_steg_mod.second->extensions)
payload_server->extension_to_content_type_map[cur_supported_extension] = cur_steg_mod.second->content_type_id();

//TODO: for now only one steg module can be mentioned for testing.
//It should be that a comma separated list should be able to
//activate
Expand Down
86 changes: 48 additions & 38 deletions src/steg/http_steg_mods/file_steg.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ ssize_t
FileStegMod::extract_appropriate_respones_body(evbuffer* payload_buf)
{
//TODO: this need to be investigated, we might need two functions
const evbuffer_ptr hend = evbuffer_search(payload_buf, "\r\n\r\n", sizeof ("\r\n\r\n") -1 , NULL);
const evbuffer_ptr hend = evbuffer_search(payload_buf, end_of_header_indicator.c_str(), end_of_header_indicator.length() -1 , NULL);
if (hend.pos == -1) {
log_debug("unable to find end of header in the HTTP respose");
return RESPONSE_INCOMPLETE;
}

return hend.pos + strlen("\r\n\r\n");
return hend.pos + end_of_header_indicator.length();

}

Expand Down Expand Up @@ -249,21 +249,19 @@ FileStegMod::http_server_transmit(evbuffer *source, conn_t *conn)
log_debug("SERVER FileSteg sends resp with hdr len %zu body len %zd",
body_offset, outbuflen);

if ((size_t)outbuflen == body_len) {
log_assert(hLen < MAX_RESP_HDR_SIZE);
newHdr.assign(cover_payload.begin(), cover_payload.begin()+hLen);
newHdrLen = hLen;

}
else { //if the length is different, then we need to update the header
alter_length_in_response_header(cover_payload, outbuflen, newHdr);
newHdrLen = newHdr.size();
//TODO: handle HTTP chunked transfer.
//We need to check if set the header has a Content-length field

if (!newHdrLen) {
log_warn("SERVER ERROR: failed to alter length field in response headerr");
_payload_server.disqualify_payload(payload_id_hash);
goto error;
}
log_assert(hLen < MAX_RESP_HDR_SIZE);
vector<uint8_t> original_header(cover_payload.begin(), cover_payload.begin()+hLen);
//now we update the header
alter_length_in_response_header(original_header, outbuflen, newHdr);
newHdrLen = newHdr.size();

if (!newHdrLen) {
log_warn("SERVER ERROR: failed to alter length field in response headerr");
_payload_server.disqualify_payload(payload_id_hash);
goto error;
}

//All is good. send it off
Expand Down Expand Up @@ -371,35 +369,47 @@ FileStegMod::http_client_receive(conn_t *conn, struct evbuffer *dest,
}

void
FileStegMod::alter_length_in_response_header(const std::vector<uint8_t>& payload_with_original_header, ssize_t new_content_length, std::vector<uint8_t>& new_header)
FileStegMod::alter_length_in_response_header(const std::vector<uint8_t>& original_header, ssize_t new_content_length, std::vector<uint8_t>& new_header)
{
static const string length_field_name = "Content-Length:";
static const string end_of_field_indicator = "\r\n";

//TODO: replace these with vector search
auto length_field_start = std::search(payload_with_original_header.begin(), payload_with_original_header.end(), length_field_name.begin(), length_field_name.end());
if (length_field_start == payload_with_original_header.end()) {
log_warn("payload with bad header. unable to find the Content-Length field");
return;
}

length_field_start += length_field_name.length();
string new_content_length_str(std::to_string(new_content_length));
vector<uint8_t>::const_iterator length_field_end;

auto length_field_end = std::search(length_field_start, payload_with_original_header.end(), end_of_field_indicator.begin(), end_of_field_indicator.end());
if (length_field_end == payload_with_original_header.end()) {
log_warn("payload with bad header. unable to find the end of Content-Length field.");
return;
}
auto length_field_start = std::search(original_header.begin(), original_header.end(), length_field_name.begin(), length_field_name.end());
if (length_field_start == original_header.end()) {
log_warn("unable to find the Content-Length field, adding the field...");

//TODO: this not the correct behavoir and can work as a descriminator.
//we need to add decocding length from chunk the client side instead

//we are addining it at the end
length_field_end = original_header.end() - end_of_header_indicator.length();
new_header.insert(new_header.end(), original_header.begin(), length_field_end);
//insert an end of field
new_header.insert(new_header.end(), end_of_field_indicator.begin(), end_of_field_indicator.end());
//insert the content-length field
new_header.insert(new_header.end(), length_field_name.begin(), length_field_name.end());

} else {

//copy the first part of the header
new_header.insert(new_header.end(), payload_with_original_header.begin(), length_field_start);
//memcpy(new_header, payload_with_original_header.data(), ((uint8_t*)length_field_start - original_header));
string new_content_length_str(std::to_string(new_content_length));
length_field_start += length_field_name.length();

length_field_end = std::search(length_field_start, original_header.end(), end_of_field_indicator.begin(), end_of_field_indicator.end());
if (length_field_end == original_header.end()) {
log_warn("payload with bad header. unable to find the end of Content-Length field.");
return;
}

//copy the first part of the header
new_header.insert(new_header.end(), original_header.begin(), length_field_start);

}

//either way copy the new length after space
new_header.push_back(' ');
new_header.insert(new_header.end(), new_content_length_str.begin(), new_content_length_str.end());

//copy the rest of the header
new_header.insert(new_header.end(), length_field_end, payload_with_original_header.end());
new_header.insert(new_header.end(), length_field_end, original_header.end());

}

Expand Down
7 changes: 5 additions & 2 deletions src/steg/http_steg_mods/file_steg.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

#include <memory>
#include <algorithm>
#include <list>
#include <math.h>

using namespace std;
Expand All @@ -29,6 +28,10 @@ class FileStegMod
const int RESPONSE_INCOMPLETE = -1;
const int RESPONSE_BAD = -2;

const string length_field_name = "Content-Length:";
const string end_of_field_indicator = "\r\n";
const string end_of_header_indicator = "\r\n\r\n";

//the payload server will be passed to us by the http steg mod
//we are going to share the payload server with other file steg mods
//Ultimately it is the http steg mod who is the owner.
Expand Down Expand Up @@ -115,7 +118,7 @@ class FileStegMod

//list of file extensions/suffix which are representing files of type
//handled by the module (e.g.: *.jpg *.jpeg etc)
const list<string> extensions;
vector<string> extensions;

/**
embed the data in the cover buffer, the assumption is that
Expand Down
6 changes: 4 additions & 2 deletions src/steg/http_steg_mods/htmlSteg.cc
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ HTMLSteg::decode_http_body(const std::vector<uint8_t>& cover_and_data, std::vect
HTMLSteg::HTMLSteg(PayloadServer& payload_provider, double noise2signal)
:JSSteg(payload_provider, noise2signal, HTTP_CONTENT_HTML)
{
//correcting the type

//adding extensions this module support
vector<string> supported_extension_list({"html", "htm", "shtml", "php"});
extensions = supported_extension_list;

}
4 changes: 4 additions & 0 deletions src/steg/http_steg_mods/jpgSteg.cc
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,8 @@ ssize_t JPGSteg::decode(const std::vector<uint8_t>& cover_payload, std::vector<u
JPGSteg::JPGSteg(PayloadServer& payload_provider, double noise2signal)
:FileStegMod(payload_provider, noise2signal, HTTP_CONTENT_JPEG)
{
//adding extensions this module support only if the type is JS (not being called by HTML CONST)
vector<string> supported_extension_list({"jpg", "jpeg"});
extensions = supported_extension_list;

}
15 changes: 11 additions & 4 deletions src/steg/http_steg_mods/jsSteg.cc
Original file line number Diff line number Diff line change
Expand Up @@ -518,13 +518,15 @@ JSSteg::encode(const std::vector<uint8_t>& data, std::vector<uint8_t>& cover_pay
return -1;
}

cover_with_data = outbuf2;
cover_payload = outbuf2;

}
} else {
//encCnt isn't really needed any more except for debugging and tracking, but return value outbuf2len is needed for new header
//return encCnt;
cover_payload = cover_with_data;
return cover_with_data.size();
cover_payload = cover_with_data;
}

return cover_payload.size();

}

Expand Down Expand Up @@ -715,6 +717,11 @@ void JSSteg::printerr(int err_no) /* name errno had conflict with other vars so
JSSteg::JSSteg(PayloadServer& payload_provider, double noise2signal, int content_type)
:FileStegMod(payload_provider, noise2signal, content_type)
{
//adding extensions this module support only if the type is JS (not being called by HTML CONST)
if (content_type == CONTENT_JAVASCRIPT) {
vector<string> supported_extension_list({"js", "JS"});
extensions = supported_extension_list;
}

}

Expand Down
Loading

0 comments on commit bd460be

Please sign in to comment.