Skip to content

Commit

Permalink
Making boost an optional dependancy only required for local http server.
Browse files Browse the repository at this point in the history
  • Loading branch information
vmon committed Feb 17, 2019
1 parent 9ab3787 commit 95461f0
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 43 deletions.
20 changes: 16 additions & 4 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,22 @@ PKG_CHECK_MODULES([libyaml], [yaml-cpp >= 0.5.0])
#PKG_CHECK_MODULES([libssl], [libssl >= 1.0.1])

# the portable c++ library for manipulating filesystem (only server needs boost)
AX_BOOST_BASE([1.46.0],, [AC_MSG_ERROR([we needs Boost, but it was not found in your system])])
AX_BOOST_SYSTEM
AX_BOOST_FILESYSTEM
# PKG_CHECK_MODULES([libboost], [libboost >= 1.46.0])
AC_ARG_WITH(boost,

[ --without-boost do not use libboost (disables integrating with local http server)])
if test "x${with_boost}" != "xno"; then
AX_BOOST_BASE([1.46.0],
[
AC_DEFINE(HAVE_BOOST, 1)
],
[AC_MSG_ERROR([we needs Boost, but it was not found in your system])
AC_DEFINE(HAVE_BOOST, 0)])
AX_BOOST_SYSTEM
AX_BOOST_FILESYSTEM
# PKG_CHECK_MODULES([libboost], [libboost >= 1.46.0])
else
AC_DEFINE(HAVE_BOOST, 0)
fi

# libraries needed for tester proxy
#PKG_CHECK_MODULES([libevent_openssl], [libevent_openssl >= 2.0])
Expand Down
8 changes: 3 additions & 5 deletions src/steg/apache_payload_server.cc
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
#include <fstream>
#include <sstream>
#include <vector>
#include <boost/filesystem.hpp>
#include <assert.h>

using namespace std;
using namespace boost::filesystem;

#include "util.h"
#include "curl_util.h"
#include "crypt.h"
Expand All @@ -17,6 +13,8 @@ using namespace boost::filesystem;
#include "http_steg_mods/jpgSteg.h"
#include "payload_scraper.h"

using namespace std;

/**
The constructor reads the payload database prepared by scraper
and initialize the payload table.
Expand Down Expand Up @@ -50,7 +48,7 @@ ApachePayloadServer::ApachePayloadServer(MachineSide init_side, const string& da
//we are in trouble need to change the type to pointer
//_payload_database.type_detail = new TypeDetail[c_no_of_steg_protocol];

if (!boost::filesystem::exists(_database_filename)) {
if (!file_exists_with_name(_database_filename)) {
log_debug("payload database does not exists.");
log_debug("scarping payloads to create the database...");

Expand Down
15 changes: 8 additions & 7 deletions src/steg/apache_payload_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <openssl/sha.h>
#include <unordered_map>
#include <string>

#include "payload_lru_cache.h"
#include "payload_server.h"
Expand All @@ -17,9 +18,9 @@ class URIEntry
bool accept_param; /*This is to discriminate between types like html
vs cgi, js, etc, but for now I'm not using it
*/
string URL;
std::string URL;

URIEntry(string init_URL)
URIEntry(std::string init_URL)
: accept_param(true),
URL(init_URL)
{
Expand All @@ -34,8 +35,8 @@ class ApachePayloadServer: public PayloadServer
friend class PayloadScraper; /* We need the url retrieving capabilities in
PayloadScraper*/
protected:
string _database_filename;
string _apache_host_name;
std::string _database_filename;
std::string _apache_host_name;

const unsigned long c_max_buffer_size;
const static unsigned int c_MAX_FETCH_TRIES = 3; //no of attemps in fetching a cover in case of curl error
Expand Down Expand Up @@ -69,7 +70,7 @@ class ApachePayloadServer: public PayloadServer
@param url_hash the sha-1 hash of the url
*/
string fetch_hashed_url(const string& url_hash);
std::string fetch_hashed_url(const std::string& url_hash);

public:
enum PayloadChoiceStrategy {
Expand All @@ -80,7 +81,7 @@ class ApachePayloadServer: public PayloadServer
public because http_apache_steg_t uses them frequently.
FIX ME: They need to be protected though*/
URIDict uri_dict;
map<string, unsigned long> uri_decode_book;
map<std::string, unsigned long> uri_decode_book;

const uint8_t* uri_dict_mac()
{
Expand Down Expand Up @@ -122,7 +123,7 @@ class ApachePayloadServer: public PayloadServer
The constructor reads the payload database prepared by scraper
and initialize the payload table.
*/
ApachePayloadServer(MachineSide init_side, const string& database_filename, const string& cover_server, const string& cover_list);
ApachePayloadServer(MachineSide init_side, const std::string& database_filename, const std::string& cover_server, const std::string& cover_list);

/** virtual functions */
virtual unsigned int find_client_payload(char* buf, int len, int type);
Expand Down
2 changes: 1 addition & 1 deletion src/steg/http_apache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ http_apache_steg_config_t::http_apache_steg_config_common_init(config_t *cfg)
if (!cfg->steg_mod_user_configs["protocol"].empty()) {
cover_server = cfg->steg_mod_user_configs["protocol"]["cover-server"] != "" ?
cfg->steg_mod_user_configs["protocol"]["cover-server"] : cover_server;

cover_list = http_steg_user_configs["cover-list"] != "" ?
http_steg_user_configs["cover-list"] : "";
}
Expand Down
1 change: 1 addition & 0 deletions src/steg/payload_lru_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <cassert>
#include <list>
#include <algorithm>

#include <util.h>
// Class providing fixed-size (by number of records)
Expand Down
46 changes: 23 additions & 23 deletions src/steg/payload_scraper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
#include <string>
#include <sstream>
#include <stdio.h>
#include <boost/filesystem.hpp>

using namespace std;
using namespace boost::filesystem;

#include "util.h"
#include "crypt.h"
Expand All @@ -28,7 +26,11 @@ using namespace boost::filesystem;
#include "base64.h"

#include "protocol/chop_blk.h" //We need this to no what's the minimum
//acceptable capacity

#if HAVE_BOOST == 1
#include <boost/filesystem.hpp>
#endif
//acceptable capacity

#define TEMP_MOUNT_DIR "/tmp/remote_www"
/** We read the /etc/httpd/conf/httpd.conf (this need to be more dynamic)
Expand Down Expand Up @@ -94,10 +96,15 @@ PayloadScraper::scrape_url(const string& cur_url, steg_type* cur_steg, bool abso
@param cur_dir the name of the dir to be scraped
*/
int
PayloadScraper::scrape_dir(const path dir_path)
PayloadScraper::scrape_dir(const string dir_string_path)
{
long int total_file_count = 0;

#if HAVE_BOOST == 1
using namespace boost::filesystem;

path dir_path(dir_string_path);

if ( !exists( dir_path ) )
return -1;

Expand All @@ -119,6 +126,10 @@ PayloadScraper::scrape_dir(const path dir_path)
}
}

#else
(void) dir_string_path;
log_abort("unable to scrape dir when made without boost");
#endif
return total_file_count;

}
Expand All @@ -136,7 +147,7 @@ PayloadScraper::scrape_url_list(const string list_filename)
long int total_file_count = 0;
std::map<std::string, bool> scraped_tracker; //keeping track of url repetition

if ( !exists( list_filename ) ) {
if ( !file_exists_with_name( list_filename ) ) {
log_warn("cover list file does not exsits.");
return -1;
}
Expand Down Expand Up @@ -273,14 +284,15 @@ int PayloadScraper::scrape()

}

if (!scrape_succeed) { //no url list is given, try to scrape file system
#if HAVE_BOOST == 1
if (!scrape_succeed) { //no url list is given, try to scrape file system only if we have
//boost
// looking for doc root dir...
// If the http server is localhost, then try read localy...
bool remote_mount = false; //true if the doc_root is mounted from remote host
string ftp_unmount_command_string = "fusermount -u ";
ftp_unmount_command_string += TEMP_MOUNT_DIR;


if (_cover_server == "127.0.0.1")
if (apache_conf_parser())
log_warn("error in retrieving apache doc root: %s",strerror(errno));
Expand Down Expand Up @@ -321,8 +333,7 @@ int PayloadScraper::scrape()
}

/* now all we need to do is to call scrape */
path dir_path(_apache_doc_root);
if (scrape_dir(dir_path) < 0)
if (scrape_dir(_apache_doc_root) < 0)
{
log_warn("error in retrieving payload dir: %s",strerror(errno));
_payload_db.close();
Expand All @@ -337,6 +348,9 @@ int PayloadScraper::scrape()
log_warn("error while trying to unmount ftp folder");
}
}
#else
(void) scrape_succeed;
#endif

_payload_db.close();
return 0;
Expand Down Expand Up @@ -391,20 +405,6 @@ int PayloadScraper::apache_conf_parser()

pair<unsigned long, unsigned long> PayloadScraper::compute_capacity(string payload_url, steg_type* cur_steg, bool absolute_url)
{
/*cur_file.open(payload_filename.c_str()); //, ios::binary | ios::in);
if (!cur_file.is_open())
{
fprintf(stderr, "Error opening payload for capacity analyze.");
continue;
}
cur_file.seekg (0, ios::end);
unsigned long cur_filelength = cur_file.tellg();*/

//Maybe we need it in future, when we are able
//to compute the capacity without using apache
//cur_file.seekg (0, ios::beg);*/
unsigned long test_cur_filelength;
stringstream payload_buf;

Expand Down
6 changes: 3 additions & 3 deletions src/steg/payload_scraper.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
struct steg_type
{
int type;
std::string extension;
std::string extension;
unsigned int (*capacity_function)(char* payload, int len);

};
Expand Down Expand Up @@ -68,13 +68,13 @@ class PayloadScraper
int scrape_url_list(const std::string list_filename);

/**
Scrapes current directory, recursively calls itself for
Scrapes a directory, recursively calls itself for
for subdirs, return number of payload if successful -1
if it fails.
@param cur_dir the name of the dir to be scraped
*/
int scrape_dir(const boost::filesystem::path cur_dir);
int scrape_dir(const std::string cur_dir);

/**
open the apache configuration file, search for DocumentRoot
Expand Down
30 changes: 30 additions & 0 deletions src/util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
#include <string>
#include <sstream>
#include <fstream>

#include "util.h"
#include "connections.h"
Expand Down Expand Up @@ -784,3 +785,32 @@ offset2Alnum_ (char *p, int range) {
return -1;
}
}

/**
* checks if a file exists
*
* @param filename the full path of the file to be checked its existance
*
* @return true if the file exists otherwise false
*/
bool file_exists_with_name(const std::string& filename) {
ifstream f(filename.c_str());
return f.good();
}

/**
* return the files if it succeed to open the file
*
* @param filename the full path of the file
*
* @return return the file size in byte or -1 if failed
*/
ssize_t file_size(const std::string& filename) {
ifstream cur_file(filename.c_str(), ios::binary | ios::ate);
if (!cur_file.good()) {
fprintf(stderr, "Error opening payload for capacity analyze.");
return -1;
}

return cur_file.tellg();
}
18 changes: 18 additions & 0 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -443,4 +443,22 @@ isalnum_ (char c);
int
offset2Alnum_(char *p, int range);

/**
* checks if a file exists
*
* @param filename the full path of the file to be checked its existance
*
* @return true if the file exists otherwise false
*/
bool file_exists_with_name(const std::string& filename);

/**
* return the files if it succeed to open the file
*
* @param filename the full path of the file
*
* @return return the file size in byte or -1 if failed
*/
ssize_t file_size(const std::string& filename);

#endif

0 comments on commit 95461f0

Please sign in to comment.