From e731c3c858f3643741bfc9b847495cfcca42d8b6 Mon Sep 17 00:00:00 2001 From: maxdcb Date: Thu, 31 Jul 2025 07:45:15 -0400 Subject: [PATCH] Fix modules for windows compatibility --- .../tests/testsEnumerateShares.cpp | 3 +++ modules/GetEnv/tests/testsGetEnv.cpp | 3 +++ modules/IpConfig/IpConfig.cpp | 18 +++++++++++++++++- modules/IpConfig/tests/testsIpConfig.cpp | 3 +++ modules/Netstat/tests/testsNetstat.cpp | 3 +++ modules/Shell/Shell.cpp | 2 ++ modules/Shell/Shell.hpp | 5 +++++ modules/Whoami/Whoami.cpp | 5 ++--- modules/Whoami/tests/testsWhoami.cpp | 3 +++ 9 files changed, 41 insertions(+), 4 deletions(-) diff --git a/modules/EnumerateShares/tests/testsEnumerateShares.cpp b/modules/EnumerateShares/tests/testsEnumerateShares.cpp index e52e298..34c64cc 100644 --- a/modules/EnumerateShares/tests/testsEnumerateShares.cpp +++ b/modules/EnumerateShares/tests/testsEnumerateShares.cpp @@ -21,5 +21,8 @@ bool testEnumerateShares() C2Message msg, ret; mod->init(cmd, msg); mod->process(msg, ret); + + std::cout << "[+] enumerateShares output: " << ret.returnvalue() << std::endl; + return !ret.returnvalue().empty(); } diff --git a/modules/GetEnv/tests/testsGetEnv.cpp b/modules/GetEnv/tests/testsGetEnv.cpp index c55f3cd..689a87d 100644 --- a/modules/GetEnv/tests/testsGetEnv.cpp +++ b/modules/GetEnv/tests/testsGetEnv.cpp @@ -22,5 +22,8 @@ bool testGetEnv() C2Message msg, ret; mod->init(cmd, msg); mod->process(msg, ret); + + std::cout << "[+] getEnv output: " << ret.returnvalue() << std::endl; + return !ret.returnvalue().empty(); } diff --git a/modules/IpConfig/IpConfig.cpp b/modules/IpConfig/IpConfig.cpp index 8555b7b..0241807 100644 --- a/modules/IpConfig/IpConfig.cpp +++ b/modules/IpConfig/IpConfig.cpp @@ -69,6 +69,22 @@ int IpConfig::process(C2Message& c2Message, C2Message& c2RetMessage) return 0; } + +#ifdef _WIN32 +std::string WideToUTF8(const PWCHAR wideStr) { + if (!wideStr) return ""; + + int len = WideCharToMultiByte(CP_UTF8, 0, wideStr, -1, nullptr, 0, nullptr, nullptr); + if (len == 0) return ""; + + std::string result(len - 1, 0); // exclude null terminator + WideCharToMultiByte(CP_UTF8, 0, wideStr, -1, &result[0], len, nullptr, nullptr); + + return result; +} +#endif + + std::string IpConfig::runIpconfig() { #ifdef _WIN32 @@ -81,7 +97,7 @@ std::string IpConfig::runIpconfig() { for(auto p = addr; p; p = p->Next) { - result += p->FriendlyName; result += "\n"; + result += WideToUTF8(p->FriendlyName) + "\n"; for(PIP_ADAPTER_UNICAST_ADDRESS unicast = p->FirstUnicastAddress; unicast; unicast = unicast->Next) { char ip[INET6_ADDRSTRLEN]; diff --git a/modules/IpConfig/tests/testsIpConfig.cpp b/modules/IpConfig/tests/testsIpConfig.cpp index f36a6d6..dc9d400 100644 --- a/modules/IpConfig/tests/testsIpConfig.cpp +++ b/modules/IpConfig/tests/testsIpConfig.cpp @@ -21,5 +21,8 @@ bool testIpConfig() C2Message msg, ret; mod->init(cmd, msg); mod->process(msg, ret); + + std::cout << "[+] ipConfig output: " << ret.returnvalue() << std::endl; + return !ret.returnvalue().empty(); } diff --git a/modules/Netstat/tests/testsNetstat.cpp b/modules/Netstat/tests/testsNetstat.cpp index 6b66a3e..a319ca0 100644 --- a/modules/Netstat/tests/testsNetstat.cpp +++ b/modules/Netstat/tests/testsNetstat.cpp @@ -21,5 +21,8 @@ bool testNetstat() C2Message msg, ret; mod->init(cmd, msg); mod->process(msg, ret); + + std::cout << "[+] netstat output: " << ret.returnvalue() << std::endl; + return !ret.returnvalue().empty(); } diff --git a/modules/Shell/Shell.cpp b/modules/Shell/Shell.cpp index 725a546..599b9f9 100644 --- a/modules/Shell/Shell.cpp +++ b/modules/Shell/Shell.cpp @@ -2,10 +2,12 @@ #include "Common.hpp" #include +#ifdef __linux__ #include #include #include #include +#endif #include using namespace std; diff --git a/modules/Shell/Shell.hpp b/modules/Shell/Shell.hpp index f72337a..e21f554 100644 --- a/modules/Shell/Shell.hpp +++ b/modules/Shell/Shell.hpp @@ -24,7 +24,12 @@ private: void stopShell(); int m_masterFd; + +#ifdef _WIN32 + int m_pid; +#else pid_t m_pid; +#endif std::string m_program; bool m_started; }; diff --git a/modules/Whoami/Whoami.cpp b/modules/Whoami/Whoami.cpp index 33c722d..37f456d 100644 --- a/modules/Whoami/Whoami.cpp +++ b/modules/Whoami/Whoami.cpp @@ -3,12 +3,11 @@ #include #include -#ifdef _WIN32 -#include -#endif #ifdef _WIN32 #include +#include +#pragma comment(lib, "Advapi32.lib") #else #include #include diff --git a/modules/Whoami/tests/testsWhoami.cpp b/modules/Whoami/tests/testsWhoami.cpp index 10f2ab1..c5ad346 100644 --- a/modules/Whoami/tests/testsWhoami.cpp +++ b/modules/Whoami/tests/testsWhoami.cpp @@ -21,5 +21,8 @@ bool testWhoami() C2Message msg, ret; mod->init(cmd, msg); mod->process(msg, ret); + + std::cout << "[+] whoami output: " << ret.returnvalue() << std::endl; + return !ret.returnvalue().empty(); }