@@ -25,6 +25,8 @@ using namespace std;
2525constexpr std::string_view moduleName = " makeToken" ;
2626constexpr unsigned long long moduleHash = djb2(moduleName);
2727
28+ #define ERROR_INVALID_ARGS 1
29+
2830
2931#ifdef _WIN32
3032
@@ -114,21 +116,28 @@ int MakeToken::init(std::vector<std::string> &splitedCmd, C2Message &c2Message)
114116
115117int MakeToken::process (C2Message &c2Message, C2Message &c2RetMessage)
116118{
117- const std::string cmd = c2Message.cmd ();
119+ const std::string cmd = c2Message.cmd ();
118120
119121 std::vector<std::string> splitedList;
120122 splitList (cmd, " ;" , splitedList);
121123
124+ c2RetMessage.set_instruction (c2RetMessage.instruction ());
125+ c2RetMessage.set_cmd (cmd);
126+
127+ if (splitedList.size () < 3 )
128+ {
129+ c2RetMessage.set_errorCode (ERROR_INVALID_ARGS);
130+ return 0 ;
131+ }
132+
122133 std::string domain=splitedList[0 ];
123134 std::string username=splitedList[1 ];
124135 std::string password=splitedList[2 ];
125136
126- std::string out = makeToken (username, domain, password);
137+ std::string out = makeToken (username, domain, password);
127138
128- c2RetMessage.set_instruction (c2RetMessage.instruction ());
129- c2RetMessage.set_cmd (cmd);
130- c2RetMessage.set_returnvalue (out);
131- return 0 ;
139+ c2RetMessage.set_returnvalue (out);
140+ return 0 ;
132141}
133142
134143// https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-logonusera
@@ -168,5 +177,18 @@ std::string MakeToken::makeToken(const std::string& username, const std::string&
168177
169178#endif
170179
171- return result;
172- }
180+ return result;
181+ }
182+
183+ int MakeToken::errorCodeToMsg (const C2Message &c2RetMessage, std::string& errorMsg)
184+ {
185+ #if defined(BUILD_TEAMSERVER) || defined(BUILD_TESTS)
186+ int errorCode = c2RetMessage.errorCode ();
187+ if (errorCode > 0 )
188+ {
189+ if (errorCode == ERROR_INVALID_ARGS)
190+ errorMsg = " Failed: Invalid arguments" ;
191+ }
192+ #endif
193+ return 0 ;
194+ }
0 commit comments