Skip to content

Commit

Permalink
added option to compile for single or multi service mode
Browse files Browse the repository at this point in the history
  • Loading branch information
fakhrizulkifli committed May 13, 2018
1 parent cd70782 commit a7a7ebb
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 9 deletions.
17 changes: 8 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
CXX = g++
CXXFLAGS = -O3 -std=c++11 -Wextra
LDFLAGS = -lcrypto
LIBS = -lcrypto
LDFLAGS = -lcrypto -lcurl -ljsoncpp
LIBS = -lcrypto -lcurl -ljsoncpp
INCS = -I./include
PROG = get_flag
SRCS = $(wildcard *.cpp)
OBJS = $(patsubst %.cpp, %.o, $(SRCS))
SUBDIRS = all clean
SUBDIRS = single multi clean

all: $(OBJS)
$(CXX) $(CXXFLAGS) -o $(PROG) $(OBJS) $(INCS) $(LDFLAGS)
single:
@$(CXX) $(SRCS) $(CXXFLAGS) -o $(PROG) $(INCS) $(LDFLAGS)

%.o: %.cpp
$(CXX) $(CXXFLAGS) -c $< $(LIBS) $(INCS) -o $@
multi:
@$(CXX) $(SRCS) $(CXXFLAGS) -o $(PROG) $(INCS) $(LDFLAGS) -DMULTISERVICE

.PHONY: $(SUBDIRS)

clean:
rm -f *.o $(PROG)
@rm -f *.o $(PROG)
21 changes: 21 additions & 0 deletions get_flag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,18 @@

#define INTERFACE "ens33"

#ifdef MULTISERVICE
#define FLAGSUBMIT_URL "http://192.168.1.5:8888/flag/submit/"
#include <unistd.h>
#include <cstdlib>
#include <cstdint>
#include <curl/curl.h>
#include <jsoncpp/json/json.h>
#include "services.h"
#else
#include "crypto.hpp"
#endif

#include "util.hpp"

int main(int argc, char **argv)
Expand All @@ -14,6 +25,15 @@ int main(int argc, char **argv)
byte *key = (byte *) "c3bb356d542b36ca5a352cd3a6276014";
EVP_add_cipher(EVP_aes_256_cbc());

#ifdef MULTISERVICE
Json::Value jsonData;
Json::Reader jsonReader;

uid_t uid = getuid();
std::string flag = util::getServiceFlag(uid);
std::cout << flag;
#else

crypto::gen_params(iv);

secure_string ptext = util::getLocalIP();
Expand All @@ -28,6 +48,7 @@ int main(int argc, char **argv)
secure_string b64text = crypto::base64_encode(ctext);

std::cout << b64text;
#endif

exit(EXIT_SUCCESS);
}
18 changes: 18 additions & 0 deletions include/services.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef SERVICES_H
#define SERVICES_H

/*
* uid - to match with the sqlite services uid
*/
struct services_info
{
int uid;
};

struct services_info service[] =
{
{1000},
{1001}
};

#endif
44 changes: 44 additions & 0 deletions include/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,49 @@

namespace util
{
#ifdef MULTISERVICE
std::size_t callback(const char *in, std::size_t size, std::size_t num, std::string *out)
{
const std::size_t totalBytes(size * num);
out->append(in, totalBytes);
return totalBytes;
}

std::string getServiceFlag(uid_t u, std::string local_ip, int s)
{
std::string uid = std::to_string(u);
const std::string flagsubmit_url(FLAGSUBMIT_URL + uid);

CURL* curl = curl_easy_init();
CURLcode res;

curl_easy_setopt(curl, CURLOPT_URL, flagsubmit_url.c_str());
curl_easy_setopt(curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);

long httpCode(0);
std::unique_ptr<std::string> httpData(new std::string());

curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, util::callback);

curl_easy_setopt(curl, CURLOPT_WRITEDATA, httpData.get());

if ((res = curl_easy_perform(curl)) != CURLE_OK)
{
exit(EXIT_FAILURE);
}

curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &httpCode);
curl_easy_cleanup(curl);

if (httpCode == 200)
return *httpData.get();

return NULL;
}
#else

extern "C"
{
#include <sys/socket.h>
Expand Down Expand Up @@ -42,6 +85,7 @@ namespace util
}
}
}
#endif
}

#endif

0 comments on commit a7a7ebb

Please sign in to comment.