Skip to content

Commit e731c3c

Browse files
committed
Fix modules for windows compatibility
1 parent 834cbeb commit e731c3c

File tree

9 files changed

+41
-4
lines changed

9 files changed

+41
-4
lines changed

modules/EnumerateShares/tests/testsEnumerateShares.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,8 @@ bool testEnumerateShares()
2121
C2Message msg, ret;
2222
mod->init(cmd, msg);
2323
mod->process(msg, ret);
24+
25+
std::cout << "[+] enumerateShares output: " << ret.returnvalue() << std::endl;
26+
2427
return !ret.returnvalue().empty();
2528
}

modules/GetEnv/tests/testsGetEnv.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,8 @@ bool testGetEnv()
2222
C2Message msg, ret;
2323
mod->init(cmd, msg);
2424
mod->process(msg, ret);
25+
26+
std::cout << "[+] getEnv output: " << ret.returnvalue() << std::endl;
27+
2528
return !ret.returnvalue().empty();
2629
}

modules/IpConfig/IpConfig.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,22 @@ int IpConfig::process(C2Message& c2Message, C2Message& c2RetMessage)
6969
return 0;
7070
}
7171

72+
73+
#ifdef _WIN32
74+
std::string WideToUTF8(const PWCHAR wideStr) {
75+
if (!wideStr) return "";
76+
77+
int len = WideCharToMultiByte(CP_UTF8, 0, wideStr, -1, nullptr, 0, nullptr, nullptr);
78+
if (len == 0) return "";
79+
80+
std::string result(len - 1, 0); // exclude null terminator
81+
WideCharToMultiByte(CP_UTF8, 0, wideStr, -1, &result[0], len, nullptr, nullptr);
82+
83+
return result;
84+
}
85+
#endif
86+
87+
7288
std::string IpConfig::runIpconfig()
7389
{
7490
#ifdef _WIN32
@@ -81,7 +97,7 @@ std::string IpConfig::runIpconfig()
8197
{
8298
for(auto p = addr; p; p = p->Next)
8399
{
84-
result += p->FriendlyName; result += "\n";
100+
result += WideToUTF8(p->FriendlyName) + "\n";
85101
for(PIP_ADAPTER_UNICAST_ADDRESS unicast = p->FirstUnicastAddress; unicast; unicast = unicast->Next)
86102
{
87103
char ip[INET6_ADDRSTRLEN];

modules/IpConfig/tests/testsIpConfig.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,8 @@ bool testIpConfig()
2121
C2Message msg, ret;
2222
mod->init(cmd, msg);
2323
mod->process(msg, ret);
24+
25+
std::cout << "[+] ipConfig output: " << ret.returnvalue() << std::endl;
26+
2427
return !ret.returnvalue().empty();
2528
}

modules/Netstat/tests/testsNetstat.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,8 @@ bool testNetstat()
2121
C2Message msg, ret;
2222
mod->init(cmd, msg);
2323
mod->process(msg, ret);
24+
25+
std::cout << "[+] netstat output: " << ret.returnvalue() << std::endl;
26+
2427
return !ret.returnvalue().empty();
2528
}

modules/Shell/Shell.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
#include "Common.hpp"
33

44
#include <cstring>
5+
#ifdef __linux__
56
#include <pty.h>
67
#include <unistd.h>
78
#include <sys/select.h>
89
#include <sys/wait.h>
10+
#endif
911
#include <chrono>
1012

1113
using namespace std;

modules/Shell/Shell.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@ class Shell : public ModuleCmd
2424
void stopShell();
2525

2626
int m_masterFd;
27+
28+
#ifdef _WIN32
29+
int m_pid;
30+
#else
2731
pid_t m_pid;
32+
#endif
2833
std::string m_program;
2934
bool m_started;
3035
};

modules/Whoami/Whoami.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33

44
#include <cstring>
55
#include <sstream>
6-
#ifdef _WIN32
7-
#include <sddl.h>
8-
#endif
96

107
#ifdef _WIN32
118
#include <windows.h>
9+
#include <sddl.h>
10+
#pragma comment(lib, "Advapi32.lib")
1211
#else
1312
#include <pwd.h>
1413
#include <unistd.h>

modules/Whoami/tests/testsWhoami.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,8 @@ bool testWhoami()
2121
C2Message msg, ret;
2222
mod->init(cmd, msg);
2323
mod->process(msg, ret);
24+
25+
std::cout << "[+] whoami output: " << ret.returnvalue() << std::endl;
26+
2427
return !ret.returnvalue().empty();
2528
}

0 commit comments

Comments
 (0)